home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DBio / DSeqPrint.cpp < prev    next >
Encoding:
Text File  |  1995-12-17  |  83.6 KB  |  2,997 lines  |  [TEXT/R*ch]

  1. // DSeqPrint.cpp
  2. // d.g.gilbert, 1991-95
  3.  
  4. #define MASKS 1
  5.  
  6. #include "DSequence.h"
  7. #include "DSeqList.h"
  8. #include "DSeqDoc.h"
  9. #include "DSeqPrint.h"
  10. #include "DREnzyme.h"
  11.  
  12. #include <ncbi.h>
  13. #include <dgg.h>
  14. #include <Dvibrant.h>
  15. #include <DControl.h>
  16. #include <DDialogText.h>
  17. #include <DWindow.h>
  18. #include <DTableView.h>
  19. #include <DApplication.h>
  20. #include <DTask.h>
  21. #include <DTracker.h>
  22. #include <DMenu.h>
  23. #include <DUtil.h>
  24.  
  25.  
  26. enum FonStyles { 
  27.     kPlain = 0, kItalic = 1, kBold = 2, kUnderline = 4 
  28.     };
  29.  
  30.  
  31. enum {
  32.  
  33.     kShadeInvert = 1,
  34.     kShadeGray50 = 2,
  35.     kShadeGray25 = 3,
  36.     kShadeGray75 = 4,
  37.     kShadeStipple50    = 5,
  38.     kShadeStipple25    = 6,
  39.     kShadeStipple75    = 7,
  40.     
  41.     mColorButHit = 1001,
  42.     mMonoButHit    = 1002,
  43.  
  44.     kFontDescent = 2,
  45.     kIndexRise = 1,
  46.  
  47.   kNameWidth  = 80,
  48.   kIndexWidth = 40,
  49.   kItemWidth  = 12,
  50.     kNucSpace     = 0, //was 2
  51.     kBasesPerLine = 60, // was 50
  52.   //kSeqWidth = kItemWidth * kBasesPerLine,
  53.     kNucBorder    = 6,
  54.     kSeqLinesPerParag = 5,
  55.     kLinesPerParag= 7, // kSeqLinesPerParag + 2; // 5 seq + top index + top spacer
  56.  
  57.     kMacdrawHeaderSize= 512
  58.     };
  59.  
  60. enum SeqRowType { kSpacer, kTopline, kSeqline };
  61.  
  62.  
  63. #if 0
  64.  
  65. #define  ShadeInvert()  { PaintRect(myRect);    TextMode(srcBIC); }
  66.  
  67.                     kShadeInvert: BEGIN
  68.                         PaintRect(myRect); 
  69.                         TextMode(srcBIC);
  70.                         END;
  71. #endif
  72.  
  73.  
  74.  
  75.  
  76. class DSeqPrintPrefs : public DWindow {
  77. public:
  78.     enum { 
  79.             kSeqPrintPrefID = 1232,
  80.             kStylePlain,kStyleItalic,kStyleBold,kStyleUnderline,
  81.             cIndexLeft, cIndexRight, cIndexTop, 
  82.             cNameLeft, cNameRight,
  83.             cColored,
  84.             cShowComplement,cThreeLetAA,cOnlyORF,
  85.             cShowAA1,cShowAA2,cShowAA3,
  86.             cShowCompAA1,cShowCompAA2,cShowCompAA3,
  87.             cShowCutpoints,cShowAllZymes,cShowExcludedCutters,cShowNoncutters
  88.             };
  89.  
  90.     static char *gNameFontName, *gBaseFontName, *gIndexFontName;
  91.     static Nlm_FonT    gNameFont, gBaseFont, gIndexFont;
  92.     static short gNameFontSize, gBaseFontSize, gIndexFontSize;
  93.     static short gNameStyle, gBaseStyle, gIndexStyle;
  94.     static Boolean gNameLeft,gNameRight,gIndexLeft,gIndexRight,gIndexTop, gColored;
  95.     static short gBasesPerLine;
  96.         // restmap prefs ..
  97.     static Boolean  gShowComplement,gThreeLetAA, gOnlyORF,
  98.                 gShowAA1,gShowAA2,gShowAA3,
  99.                 gShowCompAA1,gShowCompAA2,gShowCompAA3,
  100.                 gShowAllZymes,gShowCutpoints,gShowExcludedCutters,gShowNoncutters;
  101.     static short    gREMinCuts, gREMaxCuts;
  102.     
  103.     static void InitGlobals();
  104.     static void SaveGlobals();
  105.  
  106.     DPopupMenu  * fNameFontMenu, * fBaseFontMenu, *fIndexFontMenu,
  107.                             * fNameStyleMenu, *fBaseStyleMenu, *fIndexStyleMenu;
  108.     DSwitchBox    * fNameSizeSw, * fBaseSizeSw, *fIndexSizeSw;
  109.     DEditText        * fREMinCuts, * fREMaxCuts, * fBasePerLine;
  110.     Boolean             fNeedSave;
  111.     
  112.     DSeqPrintPrefs();
  113.     virtual ~DSeqPrintPrefs();
  114.     virtual void Initialize();
  115.     virtual void Open();
  116.     virtual void Close();
  117.     virtual void OkayAction();
  118.     virtual Boolean IsMyAction(DTaskMaster* action); 
  119.     virtual void NewFontCluster(char* title, DView* mainview,
  120.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  121.                     char* fontname, short fontstyle, short fontsize );
  122.                     
  123. };
  124.  
  125. Global DSeqPrintPrefs* gSeqPrintPrefs = NULL;
  126.  
  127. char* DSeqPrintPrefs::gNameFontName = (char*) "times";
  128. char* DSeqPrintPrefs::gBaseFontName = (char*) "courier";
  129. char* DSeqPrintPrefs::gIndexFontName = (char*) "times";
  130. Nlm_FonT 
  131.             DSeqPrintPrefs::gNameFont = NULL, 
  132.              DSeqPrintPrefs::gBaseFont = NULL, 
  133.           DSeqPrintPrefs::gIndexFont = NULL;
  134. short 
  135.             DSeqPrintPrefs::gNameFontSize = 10, 
  136.             DSeqPrintPrefs::gBaseFontSize = 10, 
  137.             DSeqPrintPrefs::gIndexFontSize = 9,
  138.             DSeqPrintPrefs::gNameStyle = 0,  
  139.             DSeqPrintPrefs::gBaseStyle = 0,  
  140.             DSeqPrintPrefs::gIndexStyle = 0;
  141. Boolean     
  142.             DSeqPrintPrefs::gNameLeft = false,
  143.             DSeqPrintPrefs::gNameRight = true,
  144.             DSeqPrintPrefs::gIndexLeft = true,
  145.             DSeqPrintPrefs::gIndexRight = false,
  146.             DSeqPrintPrefs::gIndexTop = true, 
  147.             DSeqPrintPrefs::gColored = true;
  148.  
  149.     // restmap prefs ..
  150. Boolean  
  151.             DSeqPrintPrefs::gShowComplement = true,
  152.             DSeqPrintPrefs::gThreeLetAA = false,
  153.             DSeqPrintPrefs::gOnlyORF = false,
  154.             DSeqPrintPrefs::gShowAA1 = false,
  155.             DSeqPrintPrefs::gShowAA2 = false,
  156.             DSeqPrintPrefs::gShowAA3 = false,
  157.             DSeqPrintPrefs::gShowCompAA1 = false,
  158.             DSeqPrintPrefs::gShowCompAA2 = false,
  159.             DSeqPrintPrefs::gShowCompAA3 = false,
  160.             DSeqPrintPrefs::gShowAllZymes = false,
  161.             DSeqPrintPrefs::gShowCutpoints = false,
  162.             DSeqPrintPrefs::gShowExcludedCutters = false,
  163.             DSeqPrintPrefs::gShowNoncutters = false;
  164. short    
  165.             DSeqPrintPrefs::gBasesPerLine = 60,
  166.             DSeqPrintPrefs::gREMinCuts = 1, 
  167.             DSeqPrintPrefs::gREMaxCuts = 999;
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. // add this to ?? dgg.c
  175. inline void RectRgn(Nlm_RegioN rgn, Nlm_RectPtr r)
  176. {
  177.     Nlm_LoadRectRgn( rgn, r->left, r->top, r->right, r->bottom);
  178. }
  179.  
  180. inline short BaseCharWidth()
  181. {
  182.     return Nlm_CharWidth('G');
  183.     //return Nlm_MaxCharWidth(); 
  184.     //return Nlm_stdCharWidth;
  185. }
  186.  
  187.  
  188. class DDrawMapRow : public DObject {
  189. public:
  190.     enum { kNoIndex = -999, kMaxLinebuf= 1024 };
  191.     static char fLinebuf[kMaxLinebuf+1];
  192.     Nlm_FonT    fFont; 
  193.     char    * fName;
  194.     short      fHeight, fRowOffset, fLinecount, fItemrow;
  195.  
  196.     DDrawMapRow() : 
  197.         fFont(NULL), fName(NULL), fHeight(Nlm_stdLineHeight), 
  198.         fRowOffset(-1), fLinecount(0), fItemrow(0) 
  199.         {}
  200.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem) {}
  201.     virtual const char* Write( short row, short col, long startitem, long stopitem) { return ""; }
  202.     virtual char* GetName(short row) { return fName; }
  203.     virtual short GetIndex(short item) { return item; }
  204.     virtual short GetHeight( Nlm_RecT& r, short row, long startitem, long stopitem) { return fHeight; }
  205.     virtual Boolean DoLeftName() { return false; }
  206.     virtual void  Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  207.                                          Nlm_RecT& viewr, Nlm_RegioN cliprgn)
  208.     {
  209.         Nlm_ClipRgn( cliprgn);
  210.     }
  211. };
  212.  
  213. char DDrawMapRow::fLinebuf[DDrawMapRow::kMaxLinebuf+1];
  214.  
  215.  
  216. class DDrawSpacer : public DDrawMapRow {
  217. public:
  218.     char *fTitle;
  219.     DDrawSpacer( char* title= NULL, Nlm_FonT itsFont = NULL) : fTitle(title) { fFont= itsFont; }
  220.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);
  221.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  222.     virtual short GetIndex(short item) { return kNoIndex; }
  223. };
  224.  
  225. void DDrawSpacer::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  226. {
  227.     if (fTitle) {
  228.         if (fFont) Nlm_SelectFont(fFont);
  229.         Nlm_MoveTo( r.left, r.bottom-2);
  230.         Nlm_PaintString(fTitle);
  231.         }
  232. }
  233.  
  234. const char* DDrawSpacer::Write( short row, short col, long startitem, long stopitem)
  235.     long  len= Min( kMaxLinebuf, stopitem-startitem);
  236.     Nlm_MemFill(fLinebuf, ' ', len);
  237.     if (fTitle) MemCpy( fLinebuf, fTitle, Min( len, StrLen(fTitle)) );
  238.     fLinebuf[len]= 0;
  239.     return fLinebuf;
  240. }
  241.  
  242.  
  243.  
  244.  
  245. class DDrawIndexRow : public DDrawMapRow {
  246. public:
  247.     Nlm_Boolean fIsUp;
  248.     short    fItemWidth;
  249.     DDrawIndexRow( Nlm_FonT itsFont, short itemWidth, Nlm_Boolean upright= true) : 
  250.         fIsUp(upright),fItemWidth(itemWidth) 
  251.         { 
  252.             fFont= itsFont; 
  253.             if (fFont) Nlm_SelectFont(fFont);
  254.             fHeight= 3 + Nlm_LineHeight();
  255.         }
  256.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);
  257.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  258.     virtual short GetIndex(short item) { return kNoIndex; }
  259. };
  260.  
  261. void DDrawIndexRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  262. {  
  263.     short atx, aty, cleft, rowtop;
  264.     short up1, up2, upFont;
  265.     
  266.     if (col>0) startitem += col;
  267.  
  268.     if (fFont) Nlm_SelectFont(fFont);
  269.     cleft= r.left; // add a bit to move over bases
  270.     if (fIsUp) {
  271.         up1= -1;
  272.         up2= -3;
  273.         upFont= -4;
  274.         rowtop= r.bottom - kIndexRise; 
  275.         }
  276.     else {
  277.         up1= 1;
  278.         up2= 3;
  279.         upFont= Nlm_FontHeight();
  280.         rowtop= r.top + kIndexRise;
  281.         }
  282.     Nlm_MoveTo( cleft, rowtop);
  283.     Nlm_LineTo( r.right, rowtop);
  284.     
  285.     cleft += fItemWidth / 2; // add a bit to put tics over bases
  286.     for (long at= startitem; at <= stopitem; at++, cleft += fItemWidth) {
  287.         atx= cleft;
  288.         aty= rowtop;
  289.         Nlm_MoveTo( atx, aty);
  290.         if (at % 10 == 4) {
  291.             char  nums[128];
  292.             sprintf(nums, "%d", at+1);  
  293.             short ws= Nlm_StringWidth(nums);
  294.             aty += up1;
  295.             Nlm_LineTo(atx, aty);
  296.             aty += upFont;
  297.             atx -= ws/2;
  298.             Nlm_MoveTo( atx, aty);
  299.             Nlm_PaintString(nums);
  300.             }        
  301.         else {
  302.           aty += up2;
  303.             Nlm_LineTo(atx, aty);
  304.             }
  305.         }
  306. }
  307.     
  308. const char*  DDrawIndexRow::Write( short row, short col, long startitem, long stopitem)
  309.     long len, i, at;
  310.     char    * numline, * ticline, *cp;
  311.     
  312.     len= Min( kMaxLinebuf / 2, stopitem-startitem);
  313.     Nlm_MemFill( fLinebuf, ' ', (len + 1)*2);
  314.     if (fIsUp) {
  315.       numline= fLinebuf;
  316.         ticline= fLinebuf + len + 1;
  317.         }
  318.     else {
  319.       ticline= fLinebuf;
  320.         numline= fLinebuf + len + 1;
  321.         }
  322.     
  323.     for (i= 0, at=startitem; i < len; i++, at++) {
  324.         if (at % 10 == 4) {
  325.             char nums[128];
  326.             short  ws;
  327.             ticline[i]= '+';
  328.           sprintf(nums, "%d", at+1);
  329.           ws= StrLen(nums);
  330.           cp= numline + i - ws / 2;
  331.           MemCpy( cp, nums, ws);
  332.             }
  333.         //else if (fIsUp) ticline[i]= '_'; 
  334.         else 
  335.             ticline[i]= '-';
  336.         }
  337.  
  338.         fLinebuf[len]= '\n'; // newline !?
  339.         len= 2*len + 1;
  340.         fLinebuf[len]= 0;
  341.         return fLinebuf;
  342. }
  343.     
  344.     
  345.  
  346. class DDrawSeqRow : public DDrawMapRow {
  347. public:
  348.     DSeqPrintView * fView;
  349.     ulong    * fColors;
  350.     DSequence * fSeq, * fTopSeq, * fBotSeq;
  351.     char    * fBases;
  352.     char    * fFirstcommon, * fCommonbase;
  353.     long         fLength;
  354.     short        fItemWidth;
  355.     DList *    fStyles;
  356.     
  357.     DDrawSeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, DSequence* itsSeq,
  358.                                  DList* itsStyles, char* name, ulong* colors);
  359.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);    
  360.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  361.     virtual DSeqStyle* GetStyle(long ibase, short masklevel, DSequence* aSeq);
  362. };
  363.  
  364.  
  365. DDrawSeqRow::DDrawSeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, DSequence* itsSeq,
  366.                                                      DList* itsStyles, char* name, ulong* colors) : 
  367.         fView(itsView), fColors(colors), 
  368.         fSeq(itsSeq), fTopSeq(NULL), fBotSeq(NULL),
  369.         fStyles( itsStyles), 
  370.         fFirstcommon(NULL), fCommonbase(NULL),
  371.         fBases(NULL), fLength(0)
  372. {  
  373.     if (fSeq) {
  374.         fBases= fSeq->Bases();
  375.         fLength= fSeq->LengthF();
  376.         }
  377.     fFont= itsFont; 
  378.     fName= name; 
  379.     if (fFont) Nlm_SelectFont(fFont);
  380.     fHeight= Nlm_LineHeight();
  381.     fItemWidth= BaseCharWidth();
  382. }
  383.  
  384.  
  385.  
  386. DSeqStyle* DDrawSeqRow::GetStyle(long ibase, short masklevel, DSequence* aSeq)
  387. {
  388.     short maskval= 0;
  389.     if (aSeq) maskval= aSeq->MaskAt(ibase, masklevel);
  390.     if (maskval>0)  
  391.         return (DSeqStyle*) fStyles->At(masklevel-1);
  392.     else
  393.         return NULL;
  394. }
  395.  
  396.  
  397. void DDrawSeqRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  398. {
  399.     enum patvals { kNoPat, kHasFillPat, kHasFramePat };
  400.     char* bases= fBases;
  401.     if (bases && startitem < fLength) {
  402.     char    ch, lastch, *b;
  403.     short    atx, aty, masklevel, maskval;
  404.     long    ibase;
  405.     ulong    newcolor, curcolor, blackcolor;
  406.     patvals  haspat= kNoPat;
  407.          DSeqStyle * style, * laststyle, * nextstyle, * topstyle, * botstyle;
  408.    
  409.         if (col>0) {
  410.             bases += col; 
  411.             startitem += col;
  412.             }
  413.         if (stopitem > fLength) stopitem= fLength;
  414.         long len= stopitem - startitem;
  415.         atx= r.left;
  416.         aty= r.bottom - 2;
  417.         
  418.         if (fFont) Nlm_SelectFont(fFont);
  419.         Nlm_Black();
  420.         Nlm_TextTransparent();
  421.         curcolor= blackcolor= Nlm_GetColor();
  422.         
  423. #if MASKS
  424.         topstyle= botstyle= NULL;
  425.         laststyle= nextstyle= NULL;
  426.         if (startitem>0) 
  427.          for (masklevel=1; masklevel<5; masklevel++) {
  428.             laststyle= GetStyle( startitem-1, masklevel, fSeq);
  429.             if (laststyle) break;
  430.             }
  431. #endif
  432.             
  433.         lastch= 0;
  434.         for (b= bases + startitem, ibase=startitem; *b && ibase<stopitem; b++, ibase++) {
  435.             Nlm_MoveTo( atx, aty);
  436.             ch= *b;
  437.             if (ch == DSequence::indelSoft) ch= DSequence::indelHard; //looks better for output...
  438.     
  439. #if MASKS
  440.             Boolean needdraw= true;
  441.             Nlm_RecT crec;
  442.             maskval= fSeq->MaskAt(ibase,0); // val for all masks
  443.             if (maskval>0) 
  444.              for (masklevel=1; needdraw && masklevel<5; masklevel++) {
  445.                     // LATER: want to allow drawing of all mask forms for each base !?
  446.                 style= GetStyle( ibase, masklevel, fSeq);
  447.                 if (style) {
  448.                     Nlm_LoadRect( &crec, atx, r.top, atx+fItemWidth, r.bottom);
  449.                     nextstyle= GetStyle( ibase+1, masklevel, fSeq);
  450.                     topstyle= GetStyle( ibase, masklevel, fTopSeq);
  451.                     botstyle= GetStyle( ibase, masklevel, fBotSeq);
  452.  
  453. #if 1
  454.                     if (style->repeatchar && fItemrow > 0 
  455.                         && fCommonbase && fFirstcommon
  456.                         && fCommonbase[ibase] != '!'
  457.                         && fItemrow > (unsigned char)fFirstcommon[ibase]
  458.                         && toupper(ch) == fCommonbase[ibase]) 
  459.                           ch= style->repeatchar;
  460. #else                    
  461.                     if (style->repeatchar && fItemrow > 0 
  462.                         && DStyleTable::fToprow 
  463.                         && ibase < DStyleTable::fToprowlen 
  464.                         && ch == DStyleTable::fToprow[ibase]) 
  465.                           ch= style->repeatchar;
  466. #endif
  467.                           
  468.                     if (style->uppercase) ch= toupper(ch);
  469.                     else if (style->lowercase) ch= tolower(ch);
  470.                     
  471.                     if (style->font && 
  472.                     (style->font != Nlm_fontInUse || style->font != DStyleTable::fLaststyle.font)) 
  473.                           Nlm_SelectFont(style->font);
  474.                          
  475.                         // this is good only w/ backcolor !?
  476.                      if (style->dofontpat) { 
  477.                         if ( haspat == kHasFillPat || 
  478.                          (Nlm_MemCmp(style->fontpattern, DStyleTable::fLaststyle.fontpattern, 8) != 0)
  479.                          ) {
  480.                              Nlm_PenPattern(style->fontpattern);  
  481.                              haspat= kHasFillPat;
  482.                              }
  483.                          }
  484.                      else if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  485.                              
  486.                     if (style->dobackcolor) { 
  487.                         newcolor= style->backcolor;
  488.                         if (curcolor != newcolor) {
  489.                             curcolor= newcolor;
  490.                             Nlm_SetColor( curcolor);  
  491.                             }
  492.                         Nlm_PaintRect(&crec);
  493.                         }  
  494.  
  495.                     if (style->dofontcolor) newcolor= style->fontcolor;
  496.                     else if (fColors) newcolor= fColors[ch-' '];
  497.                     else newcolor= blackcolor;  
  498.                     if (curcolor != newcolor) {
  499.                         curcolor= newcolor;
  500.                         Nlm_SetColor( curcolor);  
  501.                         }
  502.  
  503.                     //if (style->invertcolor) Nlm_InvertColors();
  504.                     //if (style->invertcolor) Nlm_EraseMode();//TextMode(srcBIC);
  505.                     
  506.                     Nlm_PaintChar(ch);
  507.                     needdraw= false;
  508.  
  509.                     //if (style->invertcolor) Nlm_CopyMode();
  510.                     if (style->invertcolor) Nlm_InvertRect( &crec);
  511.                     
  512.                     if (style->frame) { 
  513.                         Boolean anyframe, leftframe, rightframe, topframe, botframe;
  514.                         leftframe = (!(laststyle && laststyle->frame));
  515.                         rightframe= (!(nextstyle && nextstyle->frame));
  516.                         topframe  = (!(topstyle && topstyle->frame));
  517.                         botframe  = (!(botstyle && botstyle->frame));
  518.                         anyframe  = leftframe||rightframe||topframe||botframe;
  519.                         
  520.                         if (anyframe) { 
  521.                           if (style->doframecolor) newcolor= style->framecolor;
  522.                             else newcolor= blackcolor; 
  523.                             if (curcolor != newcolor) {
  524.                                 curcolor= newcolor;
  525.                                 Nlm_SetColor( curcolor);  
  526.                                 }
  527.                              if (style->framestyle) { 
  528.                                  switch (style->framestyle) {
  529.                                      case DSeqStyle::kFrameSolid : Nlm_Solid(); break;
  530.                                      case DSeqStyle::kFrameDark  : Nlm_Dark(); break;
  531.                                      case DSeqStyle::kFrameMedium: Nlm_Medium(); break;
  532.                                      case DSeqStyle::kFrameLight : Nlm_Light(); break;
  533.                                      case DSeqStyle::kFrameDotted: Nlm_Dotted(); break;
  534.                                      case DSeqStyle::kFrameDashed: Nlm_Dashed(); break;
  535.                                      }
  536.                                  }
  537.                              haspat= kHasFramePat;
  538.                             }
  539.  
  540.                         if (leftframe) { 
  541.                             Nlm_MoveTo(crec.left,crec.top); 
  542.                             Nlm_LineTo(crec.left,crec.bottom); 
  543.                             } 
  544.                         if (rightframe) { 
  545.                             Nlm_MoveTo(crec.right-1,crec.top); 
  546.                             Nlm_LineTo(crec.right-1,crec.bottom); 
  547.                             } 
  548.                         if (topframe) { 
  549.                             Nlm_MoveTo(crec.left,crec.top); 
  550.                             Nlm_LineTo(crec.right,crec.top); 
  551.                             } 
  552.                         if (botframe) { 
  553.                             Nlm_MoveTo(crec.left,crec.bottom-1); 
  554.                             Nlm_LineTo(crec.right,crec.bottom-1); 
  555.                             } 
  556.                         if (anyframe) Nlm_TextTransparent(); // MSWin LineTo/DrawLine resets Opaque!
  557.                         }
  558.  
  559.                     DStyleTable::fLaststyle= *style;
  560.                     laststyle= style;
  561.                     }
  562.                 }
  563.             
  564.             if (needdraw) {
  565.                 if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  566.                  if (Nlm_fontInUse != fFont) Nlm_SelectFont(fFont); 
  567.                 if (fColors) {
  568.                     newcolor= fColors[ch-' '];
  569.                     if (curcolor != newcolor) {
  570.                         curcolor= newcolor;
  571.                         Nlm_SetColor( curcolor);  
  572.                         }
  573.                     }
  574.                 else if (curcolor != blackcolor) {
  575.                     Nlm_Black(); // if WithStyle left a color set.... !!
  576.                     curcolor= blackcolor;
  577.                     }
  578.                 Nlm_PaintChar(ch);
  579.                 laststyle= NULL;
  580.                 }
  581.  
  582. #else
  583.              if (fColors) {
  584.                  // if (swapBackcolor) Nlm_SetBackColor( fColors[ch-' ']); else 
  585.                 if (ch!=lastch) Nlm_SetColor( fColors[ch-' ']);
  586.                 }
  587.             Nlm_PaintChar(ch);
  588. #endif
  589.             lastch= ch;
  590.             atx += fItemWidth;   
  591.             }    
  592.         Nlm_TextOpaque();
  593.         Nlm_Black();
  594.         if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  595.         curcolor= blackcolor;
  596.         }
  597. }
  598.  
  599. const char* DDrawSeqRow::Write( short row, short col, long startitem, long stopitem)
  600.     long  len, i;
  601.     char* bases= fBases;
  602.     len= Min( kMaxLinebuf, stopitem-startitem);
  603.     if (bases && startitem < fLength) {
  604.     char    ch, *b;
  605.         if (stopitem > fLength) stopitem= fLength;        
  606.         for (b= bases + startitem, i=0; *b && i<len; b++, i++) {
  607.             ch= *b;
  608.             if (ch == DSequence::indelSoft) ch= DSequence::indelHard; //looks better
  609.             fLinebuf[i]= ch;
  610.             }    
  611.         for ( ; i<len; i++) fLinebuf[i]= ' ';
  612.         }
  613.     fLinebuf[len]= 0;
  614.     return fLinebuf;
  615. }
  616.     
  617.     
  618.  
  619. class DDrawManySeqRow : public DDrawSeqRow {
  620. public:
  621.     DSeqList * fSeqList;
  622.     //short             fLinesPerparag, fTopPerparag;
  623.     
  624.     DDrawManySeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, 
  625.                                     DSeqList* seqlist, long seqIndex, DList* itsStyles, ulong* colors,
  626.                                     char* commonbases, char* firstcommon);
  627. #if 0
  628.     virtual ~DDrawManySeqRow();
  629.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);    
  630.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  631.     virtual char* GetName(short row);
  632. #endif
  633. };
  634.  
  635.  
  636. DDrawManySeqRow::DDrawManySeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, 
  637.                                             DSeqList* seqlist, long seqIndex, DList* itsStyles, ulong* colors,
  638.                                             char* commonbases, char* firstcommon) : 
  639.       DDrawSeqRow( itsFont, itsView, NULL, itsStyles, NULL, colors),
  640.         fSeqList(seqlist)
  641. {
  642.     fItemrow= seqIndex;
  643.     fSeq= seqlist->SeqAt( fItemrow);
  644.     if (fSeq) {
  645.         fName= fSeq->Name();
  646.         fBases= fSeq->Bases();
  647.         fLength= fSeq->LengthF();
  648.         }
  649.     fTopSeq= seqlist->SeqAt(fItemrow-1);
  650.     fBotSeq= seqlist->SeqAt(fItemrow+1);
  651.     fCommonbase= commonbases;
  652.     fFirstcommon= firstcommon;
  653.     //fCommonbase= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, fFirstcommon);
  654. }
  655.  
  656. #if 0
  657. DDrawManySeqRow::~DDrawManySeqRow()
  658. {
  659. }
  660.  
  661. char* DDrawManySeqRow::GetName(short row)
  662. {
  663.     //DSequence* aSeq= NULL;
  664.     //short atseq= (row % fLinesPerparag) - fTopPerparag;
  665.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At( fItemrow);
  666.     //if (fSeq) return fSeq->Name(); else 
  667.     return fName;
  668. }
  669.  
  670. void DDrawManySeqRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  671. {
  672.     //DSequence* aSeq= NULL;
  673. //    short atseq= (row % fLinesPerparag) - fTopPerparag; // == fItemrow
  674.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At(fItemrow);
  675.     if (fSeq) {
  676.         //fSeq= aSeq;
  677.         //fTopSeq= (DSequence*) fSeqList->At(fItemrow-1);
  678.         //fBotSeq= (DSequence*) fSeqList->At(fItemrow+1);
  679.         //fBases= aSeq->Bases();
  680.         //fLength= aSeq->LengthF();
  681.       DDrawSeqRow::Draw( r, row, col, startitem, stopitem);
  682.         }
  683. }
  684.  
  685. const char* DDrawManySeqRow::Write( short row, short col, long startitem, long stopitem)
  686.     //DSequence* aSeq= NULL;
  687. //    short atseq= (row % fLinesPerparag) - fTopPerparag;
  688.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At(fItemrow);
  689.     if (fSeq) {
  690.         //fSeq= aSeq;
  691.         //fBases= aSeq->Bases();
  692.         //fLength= aSeq->LengthF();
  693.       return DDrawSeqRow::Write( row, col, startitem, stopitem);
  694.         }
  695.     else
  696.         return "";
  697. }
  698.  
  699. #endif
  700.  
  701.  
  702.  
  703. class DDrawAminoRow : public DDrawMapRow {
  704. public:
  705.     char        fNameStore[20];
  706.     char        * fBases;
  707.     short        fFrame, fItemWidth;
  708.     Boolean fThreeLet, fOnlyORF;
  709.     DSequence * fAAseq;
  710.     long        fLength;
  711.     
  712.     DDrawAminoRow(Nlm_FonT itsFont, DSequence* itsSeq, short frame);
  713.     virtual ~DDrawAminoRow() { if (fAAseq) delete fAAseq; }
  714.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);    
  715.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  716.     virtual short GetIndex(short item) { return kNoIndex; }
  717. };
  718.  
  719.  
  720. DDrawAminoRow::DDrawAminoRow(Nlm_FonT itsFont, DSequence* itsSeq, short frame) : 
  721.         fAAseq(NULL), fFrame( frame), fLength(0), 
  722.         fOnlyORF(DSeqPrintPrefs::gOnlyORF),
  723.         fThreeLet(DSeqPrintPrefs::gThreeLetAA) 
  724. {
  725.     Boolean iscomp = frame > 2;
  726.     short   offset = frame % 3;
  727.     fFont= itsFont;
  728.     if (fFont) Nlm_SelectFont(fFont);
  729.     fHeight= Nlm_LineHeight();
  730.     fItemWidth= BaseCharWidth();
  731.     sprintf( fNameStore, "aa%d", frame);
  732.     fName= fNameStore;
  733.     if (iscomp) {
  734.         itsSeq->SetSelection( -1,-1);
  735.         itsSeq= itsSeq->Reverse();
  736.             // strange patches...
  737.         if (offset==1) offset= 2;     
  738.         else if (offset==2) offset= 1; 
  739.         if (offset==2) itsSeq->InsertSpacers(itsSeq->LengthF(),offset,'?');   
  740.         }
  741.     itsSeq->SetSelection( offset, itsSeq->LengthF() - offset);
  742.     fAAseq= itsSeq->Translate(false);
  743.     if (iscomp) { delete itsSeq; itsSeq= NULL; }
  744.     if (fAAseq) {
  745.         fBases= fAAseq->Bases();
  746.         fLength= fAAseq->LengthF();
  747.         if (fOnlyORF) {
  748.             long    i;
  749.             Boolean isorf;
  750.             char startamino= DCodons::startamino();
  751.             for (isorf= true, i= 0; i<fLength; i++) {
  752.                 if (isorf) {
  753.                   if (fBases[i] == '*') isorf= false;
  754.                   }
  755.                 else {
  756.                      if (fBases[i] == startamino) isorf= true;
  757.                      if (!isorf) fBases[i]= ' ';
  758.                     }
  759.                 }
  760.             }
  761.         if (iscomp) { 
  762.             fAAseq->SetSelection( -1,-1);
  763.             DSequence* unrevAA= fAAseq->Reverse(); 
  764.             delete fAAseq; 
  765.             fAAseq= unrevAA; 
  766.             fBases= fAAseq->Bases();
  767.             fLength= fAAseq->LengthF();
  768.             }
  769.         }
  770. }
  771.  
  772. void DDrawAminoRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  773. {
  774.     long   len;
  775.     short  leftindent;
  776.     char*  bases= fBases;
  777.     if (bases) {
  778.         if (col) {
  779.             bases += col; 
  780.             startitem += col;
  781.             }
  782. #if 0
  783.       short indents[3,3] = {
  784.                           {0,1,2},
  785.                                                 {2,0,1},
  786.                                               {1,2,0}
  787.                                                 };
  788.         // at   0 -> 0,1,2 now & want          0%3=0
  789.         // at  50 -> 2,0,1 now -> 1,2,0 want  50%3=2
  790.         // at 100 -> 1,2,0 now -> 2,0,1 want 100%3=1
  791.         // at 150 -> 0,1,2 now & want        150%3=0
  792. #endif
  793.         leftindent=  (fFrame + (3 - (startitem % 3)) % 3) % 3; 
  794.         
  795.         len= (stopitem - startitem + 2) / 3;
  796.         startitem = (startitem + 2) / 3;  // adjust for 3-to-1 NA-to-AA translate
  797.         if (startitem + len > fLength) len= fLength - startitem;
  798.         if (startitem < fLength) {
  799.         char     *b;
  800.         short  chleft, chvert, chwidth;
  801.             
  802.             chvert= r.bottom-2;
  803.             chwidth = fItemWidth; 
  804.             chleft = r.left + chwidth * leftindent;    
  805.             chwidth *= 3;    
  806.             if (fFont) Nlm_SelectFont(fFont);
  807.             if (fThreeLet) for (b= bases+startitem; *b && len; b++, len--) {
  808.                 Nlm_MoveTo( chleft, chvert);
  809.                 Nlm_PaintString( (char*) DSequence::Amino123(*b));
  810.                 chleft += chwidth;
  811.                 }
  812.             else for (b= bases+startitem; *b && len; b++, len--) {
  813.                 Nlm_MoveTo( chleft, chvert);
  814.                 Nlm_PaintChar(*b);
  815.                 chleft += chwidth;
  816.                 }        
  817.             }
  818.         }
  819. }
  820.  
  821. const char* DDrawAminoRow::Write( short row, short col, long startitem, long stopitem)
  822.     long   len, alen;
  823.     short  leftindent;
  824.     char*  bases= fBases;
  825.     if (bases) {
  826.         len= Min( kMaxLinebuf, 1+stopitem-startitem);
  827.         Nlm_MemFill( fLinebuf, ' ', len);
  828.         
  829.         leftindent=  (fFrame + (3 - (startitem % 3)) % 3) % 3; 
  830.         
  831.         alen= (stopitem - startitem + 2) / 3;
  832.         startitem = (startitem + 2) / 3;  // adjust for 3-to-1 NA-to-AA translate
  833.         if (startitem + alen > fLength) alen= fLength - startitem;
  834.         if (startitem < fLength) {
  835.         char    *b, *cp;
  836.         long    i;
  837.             i= leftindent;    
  838.             if (fThreeLet) 
  839.              for (b= bases+startitem; *b && alen && i<len; b++, alen--, i += 3) {
  840.                 char * amino3= (char*) DSequence::Amino123(*b);
  841.                 cp= fLinebuf + i;
  842.                 MemCpy( cp, amino3, 3);
  843.                 }
  844.             else 
  845.              for (b= bases+startitem; *b && alen && i<len; b++, alen--, i += 3) {
  846.                 fLinebuf[i]= *b;
  847.                 }        
  848.             }
  849.         }
  850.     fLinebuf[len]= 0;
  851.     return fLinebuf;
  852. }
  853.     
  854.  
  855.  
  856. class DDrawZymeTable : public DDrawMapRow { 
  857. public:
  858.     char** fLinelist;
  859.     char * fTableTitle;
  860.     
  861.     DDrawZymeTable(Nlm_FonT itsFont, DREMap* itsREMap, short rowoffset);
  862.     virtual ~DDrawZymeTable();
  863.     virtual void Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);    
  864.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  865.     virtual short GetIndex(short item) { return kNoIndex; }
  866.     virtual char* TableLine(short atline); 
  867.     virtual void  Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  868.                                              Nlm_RecT& viewr, Nlm_RegioN cliprgn);
  869. };
  870.  
  871. class DDrawAllZymeTable : public DDrawZymeTable { 
  872. public:
  873.     DDrawAllZymeTable(Nlm_FonT itsFont, DREMap* itsREMap, short rowoffset);
  874. };
  875.  
  876. class DDrawNocutZymeTable : public DDrawZymeTable { 
  877. public:
  878.     DDrawNocutZymeTable(Nlm_FonT itsFont, DREMap* itsREMap, short rowoffset, 
  879.                                             short mincuts = 0, short maxcuts = 0);
  880. };
  881.  
  882.  
  883. DDrawZymeTable::DDrawZymeTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  884.         fLinelist(NULL)
  885. {
  886.   fName= "";
  887.     fFont= itsFont;
  888.     if (fFont) Nlm_SelectFont(fFont);
  889.     fHeight= Nlm_LineHeight(); 
  890.     fTableTitle= "TABLE of enzymes";
  891.     fRowOffset= rowoffset;
  892. }
  893.  
  894. DDrawZymeTable::~DDrawZymeTable() 
  895.     for (short i=0; i<fLinecount; i++) MemFree( fLinelist[i]);
  896.     MemFree( fLinelist); 
  897. }
  898.  
  899.  
  900. char* DDrawZymeTable::TableLine(short atline) 
  901.     //if (atline == 0) return fTableTitle; else 
  902.     if (atline>=0 && atline<fLinecount) return fLinelist[atline];  
  903.     else return "";
  904. }
  905.  
  906. void  DDrawZymeTable::Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  907.                                          Nlm_RecT& viewr, Nlm_RegioN cliprgn)
  908. {
  909.     //Nlm_ClipRgn( cliprgn);
  910.     Nlm_RecT clipr= r;
  911.     clipr.left= viewr.left + 10;
  912.     clipr.right= viewr.right - 10;
  913.     clipr.bottom= Min( r.bottom, viewr.bottom);
  914.     clipr.top= Max(r.top, viewr.top);
  915.     Nlm_ClipRect( &clipr);
  916. }
  917.  
  918. void DDrawZymeTable::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  919. {
  920.     short     chleft, chvert, atline;
  921.     char  * tabline;
  922.     
  923.     chleft = r.left;
  924.     chvert = r.bottom-2;
  925.     atline = row - fRowOffset;
  926.     tabline= TableLine(atline);
  927.     if (tabline) {
  928.         if (col) { 
  929.           if (StrLen(tabline)>col) tabline += col; // ??? offset TableLine by # cols ?
  930.             else tabline= "";
  931.             }
  932.         if (fFont) Nlm_SelectFont(fFont);
  933.       if (atline == 0) {
  934.             Nlm_MoveTo( chleft, chvert-1);
  935.              Nlm_PaintString( tabline);
  936.             Nlm_MoveTo( r.left, r.bottom-1);
  937.             Nlm_LineTo( r.right, r.bottom-1);
  938.           }
  939.         else if (atline >= 0 && atline < fLinecount) {
  940.             Nlm_MoveTo( chleft, chvert);
  941.             Nlm_PaintString( tabline);
  942.             }
  943.         }
  944. }
  945.  
  946. const char* DDrawZymeTable::Write( short row, short col, long startitem, long stopitem)
  947.     long   len, atline;
  948.     char   * cp;
  949.  
  950.     atline = row - fRowOffset;
  951.     len= Min( kMaxLinebuf, 80);
  952.   if (atline == 0) {
  953.         Nlm_MemFill( fLinebuf, '_', len);
  954.          StrCpy( fLinebuf, TableLine(atline));
  955.          cp= StrChr(fLinebuf, '\0');
  956.          if (cp) *cp= ' ';
  957.       }
  958.     else if (atline >= 0 && atline < fLinecount) {
  959.         Nlm_MemFill( fLinebuf, ' ', len);
  960.         cp = TableLine(atline);
  961.         StrCpy( fLinebuf, cp);
  962.          cp= StrChr(fLinebuf, '\0');
  963.          if (cp) *cp= ' ';
  964.         }
  965.     else {
  966.         Nlm_MemFill( fLinebuf, ' ', len);
  967.         }
  968.     fLinebuf[len]= 0;
  969.     return fLinebuf;
  970. }
  971.  
  972.  
  973.  
  974. DDrawAllZymeTable::DDrawAllZymeTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  975.         DDrawZymeTable( itsFont, itsREMap, rowoffset)
  976.     fTableTitle= "TABLE of all enzymes";
  977.     if (1) {
  978.         char  * zymeline = NULL;
  979.         long  i, nzymes, linelen, linecount;
  980.         char  buf[128], comma;
  981.  
  982.         nzymes= DREMap::fREnzymes->GetSize();
  983.         linecount= 4 + nzymes / 4;
  984.         fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  985.         fLinecount= 0;
  986.         sprintf( buf, "  TABLE of All Enzymes  (name: cut count)");
  987.         fLinelist[fLinecount++]= StrDup(buf);
  988.         //sprintf( buf, " ");
  989.         //fLinelist[fLinecount++]= StrDup(buf);
  990.     
  991.         for (i=0, comma = ','; i<nzymes; i++) {
  992.             if (i == nzymes-1) comma= ' ';
  993.             DREnzyme* re= (DREnzyme*) DREMap::fREnzymes->At(i);
  994.             if (re) {
  995.                 //sprintf( buf, "%10s:%3d%c  ", re->fName, re->fCutcount, comma);
  996.                 sprintf( buf, "%9s:%3d  ", re->fName, re->fCutcount, comma);
  997.                 if (zymeline)  
  998.                     zymeline= Dgg_StrExtendCat( &zymeline, buf);
  999.                 else {
  1000.                     zymeline= StrDup(buf);
  1001.                     }
  1002.               linelen= StrLen(zymeline);
  1003.                 if (linelen > 70) {
  1004.                     fLinelist[fLinecount++]= zymeline;
  1005.                     zymeline= NULL;
  1006.                     }
  1007.                 }
  1008.  
  1009.           if (fLinecount >= linecount) {
  1010.               linecount += 10;
  1011.               fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  1012.               }
  1013.             }
  1014.         if (zymeline) fLinelist[fLinecount++]= zymeline;
  1015.         }
  1016. }
  1017.  
  1018.  
  1019. DDrawNocutZymeTable::DDrawNocutZymeTable( Nlm_FonT itsFont, DREMap * itsREMap,
  1020.              short rowoffset, short mincuts, short maxcuts) :
  1021.         DDrawZymeTable( itsFont, itsREMap, rowoffset)
  1022.     if (maxcuts) fTableTitle= "TABLE of excluded enzymes";
  1023.     else fTableTitle= "TABLE of non-cutting enzymes";
  1024.     if (1) {
  1025.         char  * zymeline = NULL;
  1026.         long  i, nzymes, linelen, linecount;
  1027.         char  buf[128], comma;
  1028.         Boolean dolist;
  1029.         
  1030.         nzymes= DREMap::fREnzymes->GetSize();
  1031.         linecount= 4 + nzymes / 6;
  1032.         fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  1033.         fLinecount= 0;
  1034.         if (maxcuts) sprintf( buf, "  TABLE of Excluded Enzymes");
  1035.         else sprintf( buf, "  TABLE of Noncutting Enzymes");
  1036.         fLinelist[fLinecount++]= StrDup(buf);
  1037.         if (maxcuts) {
  1038.             sprintf( buf, "  (cut with less than %d or more than %d cuts)", mincuts, maxcuts);
  1039.             fLinelist[fLinecount++]= StrDup(buf);
  1040.             }
  1041.             
  1042.         for (i=0, comma = ','; i<nzymes; i++) {
  1043.             //if (i == nzymes-1) comma= ' ';
  1044.             DREnzyme* re= (DREnzyme*) DREMap::fREnzymes->At(i);
  1045.             if (re) {
  1046.                 if (maxcuts)  
  1047.                     dolist= (re->fCutcount > 0 && (re->fCutcount < mincuts || re->fCutcount > maxcuts));  
  1048.                 else 
  1049.                     dolist= re->fCutcount == 0;
  1050.                 if (dolist) {
  1051.                     //sprintf( buf, "%9s%c ", re->fName,comma);
  1052.                     sprintf( buf, "%9s ", re->fName);
  1053.                     if (zymeline)  
  1054.                         zymeline= Dgg_StrExtendCat( &zymeline, buf);
  1055.                     else {
  1056.                         zymeline= StrDup(buf);
  1057.                         }
  1058.                   linelen= StrLen(zymeline);
  1059.                     if (linelen > 60) {
  1060.                         fLinelist[fLinecount++]= zymeline;
  1061.                         zymeline= NULL;
  1062.                         }
  1063.                     }
  1064.                 }
  1065.  
  1066.           if (fLinecount >= linecount) {
  1067.               linecount += 10;
  1068.               fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  1069.               }
  1070.             }
  1071.         if (zymeline) fLinelist[fLinecount++]= zymeline;
  1072.         }
  1073. }
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082. class DDrawZymeCutTable : public DDrawZymeTable { 
  1083. public:
  1084.     DRECutsItem * fCutList;               
  1085.     long    fCutcount;
  1086.     short    fCuttersCount;             //# zymes that cut
  1087.     
  1088.     DDrawZymeCutTable(Nlm_FonT itsFont, DREMap* itsREMap, short rowoffset);
  1089.     virtual ~DDrawZymeCutTable();
  1090.     virtual char* TableLine(short atline); 
  1091.     virtual char* GetName(short row); 
  1092.     virtual Boolean DoLeftName() { return true; }
  1093. };
  1094.  
  1095.  
  1096. #ifdef WIN_MSWIN
  1097. static int LIBCALLBACK
  1098. #else
  1099. static int
  1100. #endif
  1101. zymenameCompare(void* a, void* b)
  1102. {
  1103.     short diff = StringCmp(((DRECutsItem*)a)->fREnzyme->fName, ((DRECutsItem*)b)->fREnzyme->fName);
  1104.     if (diff == 0) {
  1105.         return ((DRECutsItem*)a)->fSeqIndex - ((DRECutsItem*)b)->fSeqIndex;
  1106.         }
  1107.     else 
  1108.         return diff;
  1109. }
  1110.  
  1111.  
  1112.  
  1113. DDrawZymeCutTable::DDrawZymeCutTable(Nlm_FonT itsFont, DREMap * itsREMap, short rowoffset) :
  1114.         DDrawZymeTable( itsFont, itsREMap, rowoffset),
  1115.         fCutList(NULL), fCutcount(0), fCuttersCount(0)
  1116.     fTableTitle= "TABLE of cut points";
  1117.     if (itsREMap) {
  1118.         fCutcount= itsREMap->fCutcount;
  1119.         fCuttersCount= itsREMap->fCuttersCount;
  1120.         fCutList= (DRECutsItem*) Nlm_MemDup( itsREMap->fSeqCuts, fCutcount * sizeof(DRECutsItem));
  1121.         if (fCutList) {
  1122.             long  i, at, lastat, linecount, linelen;
  1123.             char  *name, *zymeline = NULL, *lastname="";
  1124.             char  buf[128];
  1125.             
  1126.             Nlm_HeapSort( fCutList, fCutcount, sizeof(DRECutsItem), zymenameCompare);
  1127.             
  1128.             // what if we need more than one line for zyme cut list !!
  1129.             for (i=0, linecount= 0; i<fCutcount; i++) {
  1130.                 name= fCutList[i].fREnzyme->fName;
  1131.                 if (StringCmp(name, lastname)!=0) linecount++;
  1132.                 lastname= name;
  1133.                 }
  1134.           linecount += 3;
  1135.             fLinelist= (char**) MemNew( linecount * sizeof(char*)); 
  1136.             
  1137.             fLinecount= 0;
  1138.             sprintf( buf, "  TABLE of Cut Points");
  1139.             fLinelist[fLinecount++]= StrDup(buf);
  1140.             //sprintf( buf, " ");
  1141.             //fLinelist[fLinecount++]= StrDup(buf);
  1142.  
  1143.           linelen= 0;
  1144.             lastname= ""; lastat= -1;
  1145.             for (i=0; i<fCutcount && fLinecount < linecount; i++) {
  1146.                 name= fCutList[i].fREnzyme->fName;
  1147.                 at= fCutList[i].fSeqIndex;
  1148.                 if (StringCmp(name, lastname)==0 && linelen<70) { 
  1149.                     if (at != lastat) {
  1150.                       sprintf(buf, " %d", at);
  1151.                         if (zymeline) { 
  1152.                           zymeline= Dgg_StrExtendCat( &zymeline, buf);
  1153.                           linelen= StrLen(zymeline);
  1154.                           }
  1155.                       }
  1156.                     }
  1157.                 else {
  1158.                     if (zymeline) fLinelist[fLinecount++]= zymeline;
  1159.                     sprintf(buf, "%s: %d", name, at);
  1160.                     zymeline= (char*) MemNew(StrLen(buf)+1);
  1161.                     Nlm_StringCpy(zymeline, buf);
  1162.                     linelen= StrLen(buf);
  1163.                     }
  1164.                     
  1165.                 lastname= name;
  1166.                 lastat= at;
  1167.               if (fLinecount >= linecount) {
  1168.                   linecount += 10;
  1169.                   fLinelist= (char**) Nlm_MemMore( fLinelist, linecount * sizeof(char*));
  1170.                   }
  1171.                 }
  1172.             if (zymeline) fLinelist[fLinecount++]= zymeline;
  1173.             }
  1174.         }
  1175. }
  1176.  
  1177.  
  1178. DDrawZymeCutTable::~DDrawZymeCutTable() 
  1179.     MemFree( fCutList); 
  1180. }
  1181.  
  1182. char* DDrawZymeCutTable::TableLine(short atline) 
  1183.     //if (atline == 0) return fTableTitle; else 
  1184.     if (atline>=0 && atline<fLinecount) {
  1185.         char * name = fLinelist[atline];
  1186.         char * cp= StrChr(name,':'); 
  1187.         if (cp) cp++; else cp= name;
  1188.         return cp;  
  1189.         }
  1190.     else return "";
  1191. }
  1192.  
  1193. char* DDrawZymeCutTable::GetName(short row) 
  1194.     enum { kNameLen = 80 };
  1195.     static char name[kNameLen];
  1196.     short atline = row - fRowOffset;
  1197.   if (atline == 0) {
  1198.         return "ENZYME";
  1199.         }
  1200.     else if (atline> 0 && atline < fLinecount) {
  1201.         StrNCpy(name, fLinelist[atline], kNameLen-1);
  1202.         name[kNameLen-1]= 0;
  1203.         char* cp= StrChr(name,':'); if (cp) *cp= 0;
  1204.         return name;
  1205.         }
  1206.     else
  1207.         return fName; 
  1208. }
  1209.  
  1210.  
  1211.  
  1212. class DDrawZymeRow : public DDrawMapRow { 
  1213. public:
  1214.   DSequence * fSeq, * fCoSeq;
  1215.     DREMap * fREMap;
  1216.     short        fMinCuts, fMaxCuts;
  1217.     DRECutsItem * fCutList;
  1218.     Boolean     fGoodMap;
  1219.     
  1220.     DDrawZymeRow( Nlm_FonT itsFont, DSequence* itsSeq);
  1221.     virtual ~DDrawZymeRow() { delete fREMap; }
  1222.     virtual short DrawOrMeasure( Nlm_Boolean doDraw, Nlm_RecT& r, short row, long startitem, long stopitem);    
  1223.     virtual void  Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem);    
  1224.     virtual const char* Write( short row, short col, long startitem, long stopitem);
  1225.     virtual short GetIndex(short item) { return kNoIndex; }
  1226.     virtual short GetHeight( Nlm_RecT& r, short row, long startitem, long stopitem); 
  1227.     virtual void  Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  1228.                                              Nlm_RecT& viewr, Nlm_RegioN cliprgn);
  1229. };
  1230.  
  1231.  
  1232. DDrawZymeRow::DDrawZymeRow(Nlm_FonT itsFont, DSequence* itsSeq) : 
  1233.       fSeq( itsSeq), fGoodMap(false), fCoSeq(NULL), fCutList(NULL),
  1234.       fMinCuts(DSeqPrintPrefs::gREMinCuts), 
  1235.       fMaxCuts(DSeqPrintPrefs::gREMaxCuts)
  1236.   fName= "zyme";
  1237.     fFont= itsFont;
  1238.     if (fFont) Nlm_SelectFont(fFont);
  1239.     fHeight= 4 * Nlm_LineHeight(); // ! need to calc line height for each row !?
  1240.     fREMap= new DREMap();
  1241.     if (fREMap) {
  1242.         fREMap->MapSeq(fSeq);
  1243.         fCoSeq= fREMap->fCoSeq;
  1244.         fCutList= fREMap->fSeqCuts;
  1245.         }
  1246.     fGoodMap= (fREMap && fCoSeq && fCutList);
  1247. }
  1248.  
  1249. void  DDrawZymeRow::Clip( Nlm_RecT& r, short row, long startitem, long stopitem,
  1250.                                          Nlm_RecT& viewr, Nlm_RegioN cliprgn)
  1251. {
  1252.     //Nlm_ClipRgn( cliprgn);
  1253.     Nlm_RecT clipr= r;
  1254.     clipr.left= viewr.left + 10;
  1255.     clipr.right= viewr.right - 10;
  1256.     clipr.bottom= Min( r.bottom, viewr.bottom);
  1257.     clipr.top= Max(r.top, viewr.top);
  1258.     Nlm_ClipRect( &clipr);
  1259. }
  1260.  
  1261.  
  1262. #define znameCenter 0
  1263.  
  1264. short DDrawZymeRow::DrawOrMeasure( Nlm_Boolean doDraw, Nlm_RecT& r, short row, long startitem, long stopitem)
  1265. {
  1266. /*==== 
  1267.         gctcggctgctgctcggctg
  1268.                 ||        | ||
  1269.              abcI    cbaII
  1270.                                     hcgX
  1271. ====*/
  1272.  
  1273.     short        nameHeight, rowLeft, rowTop;
  1274.     short        chwidth, chleft, ncuts, cutindx;
  1275.     short        cuts, wd, ws, rowBot, lasti, i;
  1276.     Nlm_PoinT        at;
  1277.     Boolean         first,overlap;
  1278.     char             * lastzyme, * zymes;    
  1279.     Nlm_RecT        fillRect, bRect, cRect;
  1280.     Nlm_RegioN     filledArea, aRgn;
  1281.  
  1282.     if (!fGoodMap) return 0;
  1283.     cutindx = 0; //cutindx= fLastZymeCut;
  1284.     fREMap->CutsAtBase( startitem, cutindx, ncuts);    //!? don't care if startbase has no cuts
  1285.     //fLastZymeCut= cutindx; // ????
  1286.     
  1287.     if (fFont) Nlm_SelectFont(fFont); 
  1288.  
  1289.     //atcellh= col;
  1290.     nameHeight= Nlm_FontHeight(); // cHeight;
  1291.     rowTop= r.top;
  1292.     rowLeft= r.left;
  1293.     rowBot= rowTop;
  1294.     chwidth= (r.right - r.left) / (stopitem - startitem); 
  1295.     
  1296.     filledArea= Nlm_CreateRgn();
  1297.     aRgn= Nlm_CreateRgn();
  1298.     
  1299.     chleft= rowLeft + kNucSpace;
  1300.     Nlm_LoadRect( &fillRect, chleft, rowTop, chleft+1, rowTop+1);
  1301.     RectRgn( filledArea, &fillRect); //must start w/ non-empty rgn
  1302.     Nlm_MoveTo( chleft, rowTop);
  1303.     for ( i= startitem; i<=stopitem; i++) {        
  1304.         while (fCutList[cutindx].fSeqIndex < i) cutindx++;  
  1305.         first= true;
  1306.         lasti= -1; 
  1307.         lastzyme= "";
  1308.         while (fCutList[cutindx].fSeqIndex == i) {
  1309.             zymes= fCutList[cutindx].fREnzyme->fName;
  1310.             cuts = fCutList[cutindx].fREnzyme->fCutcount;
  1311.             cutindx++;
  1312.             if (cuts < fMinCuts || cuts > fMaxCuts)  goto nextZyme;  
  1313.                 //! Kludge til we fix REMap to stop dups
  1314.             if ( i==lasti && StringCmp(zymes,lastzyme)==0) goto nextZyme; 
  1315.             lasti= i; 
  1316.             lastzyme= zymes;
  1317.             
  1318.             if (first) {
  1319.                 Nlm_MoveTo( chleft, rowTop);
  1320.                 if (doDraw) Nlm_LineTo( chleft, rowTop+2/*kTicSize*/);
  1321.                 else Nlm_MoveTo( chleft, rowTop+2);
  1322.                 }
  1323.  
  1324.             ws= Nlm_StringWidth( zymes);
  1325.             wd= 2 + ws / 2;
  1326.             do {
  1327.                 Nlm_GetPen( &at);
  1328. #if znameCenter
  1329.                 Nlm_LoadRect( &cRect, at.x-wd, at.y, at.x+wd, at.y+nameHeight);
  1330. #else
  1331.                 Nlm_LoadRect( &cRect, at.x-1, at.y, at.x+ws+1, at.y+nameHeight);
  1332. #endif
  1333.                 overlap= Nlm_RectInRgn( &cRect, filledArea); 
  1334.             
  1335.                 if (doDraw && overlap && !first) {
  1336.                     //!? replace this w/ draw top to bottom of line, then overwrite zyme names 
  1337.                     Nlm_LoadRect( &bRect, at.x, at.y-nameHeight, at.x+1, at.y);
  1338.                     if (!Nlm_RectInRgn( &bRect, filledArea)) {
  1339.                         Nlm_MoveTo( chleft, at.y-nameHeight+1);
  1340.                         Nlm_LineTo( chleft, at.y);
  1341.                         }
  1342.                     }
  1343.                 first= false;
  1344.                 Nlm_MoveTo( chleft, at.y+nameHeight);
  1345.             } while (overlap);
  1346.     
  1347.             RectRgn( aRgn, &cRect);
  1348.             Nlm_UnionRgn(filledArea, aRgn, filledArea);
  1349. #if znameCenter
  1350.             Nlm_MoveTo( chleft - (ws / 2), at.y+nameHeight);
  1351. #else
  1352.             Nlm_MoveTo( chleft, at.y+nameHeight);
  1353. #endif
  1354.             if (doDraw) {
  1355.                 //TextMode(srcCopy);  //erase line overlaps...
  1356.                 Nlm_PaintString( zymes); 
  1357.                 //TextMode(srcOr);
  1358.                 }
  1359.             Nlm_GetPen( &at);
  1360.             rowBot = Max( rowBot, at.y);   
  1361. nextZyme:            
  1362.             lasti= i;
  1363.             }
  1364.             
  1365.         //spaceright();
  1366.         //chright= chleft + GetColWidth(atCellh) - fColInset;
  1367.         //chleft = chright + fColInset;
  1368.         //atcellh++;
  1369.         chleft += chwidth;
  1370.         }
  1371.     Nlm_DestroyRgn( filledArea);
  1372.     Nlm_DestroyRgn( aRgn);
  1373.     return (rowBot - rowTop + 2); //+ 12); /* lineHeight + fudge factor*/    
  1374. }
  1375.  
  1376.  
  1377.  
  1378.  
  1379. const char* DDrawZymeRow::Write( short row, short col, long startitem, long stopitem)
  1380. /*==== 
  1381.         gctcggctgctgctcggctg
  1382.                 ||        | ||
  1383.              abcI    cbaII
  1384.                                     hcgX
  1385. ====*/
  1386.  
  1387.     short        chleft, ncuts, cutindx;
  1388.     short        cuts, ws, lasti;
  1389.     Boolean         first,overlap;
  1390.     char             * lastzyme, * zymes;    
  1391.  
  1392.     short    linelen;
  1393.     long  len, i, nlines, maxlines;
  1394.     char ** lines;
  1395.     short zlen, zat, atleft, atline;
  1396.  
  1397.  
  1398.     if (!fGoodMap) return 0;
  1399.     len= Min( kMaxLinebuf, stopitem-startitem);
  1400.     Nlm_MemFill( fLinebuf, ' ', kMaxLinebuf);
  1401.  
  1402.     linelen= stopitem-startitem + 5; // +2;
  1403.     maxlines= kMaxLinebuf / linelen;
  1404.     lines= (char**) MemNew( (maxlines+1) * sizeof(char*));
  1405.     for (i=0; i<maxlines; i++) lines[i]= fLinebuf + (linelen * i);
  1406.     nlines= 0;
  1407.     
  1408.     cutindx = 0; //cutindx= fLastZymeCut;
  1409.     fREMap->CutsAtBase( startitem, cutindx, ncuts);    //!? don't care if startbase has no cuts
  1410.     //fLastZymeCut= cutindx; // ????
  1411.         
  1412.     for ( i= startitem; i<=stopitem; i++) {        
  1413.         while (fCutList[cutindx].fSeqIndex < i) cutindx++;  
  1414.         first= true;
  1415.         lasti= -1; 
  1416.         lastzyme= "";
  1417.         chleft= i - startitem;
  1418.         while (fCutList[cutindx].fSeqIndex == i) {
  1419.             zymes= fCutList[cutindx].fREnzyme->fName;
  1420.             cuts = fCutList[cutindx].fREnzyme->fCutcount;
  1421.             cutindx++;
  1422.             if (cuts < fMinCuts || cuts > fMaxCuts)  goto nextZyme;  
  1423.                 //! Kludge til we fix REMap to stop dups
  1424.             if ( i==lasti && StringCmp(zymes,lastzyme)==0) goto nextZyme; 
  1425.             lasti= i; 
  1426.             lastzyme= zymes;
  1427.             
  1428.             if (first) {
  1429.                 lines[0][chleft]= '|';
  1430.                 first= false;
  1431.                 }
  1432.  
  1433.             ws= StrLen( zymes);
  1434. #if znameCenter
  1435.             wd= ws / 2;
  1436.             atleft= chleft - wd;
  1437. #else
  1438.             atleft= chleft;
  1439. #endif
  1440.             atline= 1;
  1441.             do {
  1442.               for (zlen=0, zat=atleft, overlap= false; zlen<ws; zlen++, zat++) 
  1443.                   if (lines[atline][zat] != ' ') { overlap= true; break; }
  1444.               if (overlap) atline++;
  1445.             } while (overlap && atline<maxlines);
  1446.             MemCpy( lines[atline]+atleft, zymes, ws);
  1447.             if (++atline > nlines) nlines= atline;
  1448.             first= false;
  1449.             
  1450. nextZyme:            
  1451.             lasti= i;
  1452.             }
  1453.             
  1454.         }
  1455.  
  1456.     //return  (rowBot - rowTop + 12); /* lineHeight + fudge factor*/    
  1457.  
  1458.     for (i=1; i<nlines; i++) *(lines[i]-1)= '\n';
  1459.     if (nlines) lines[nlines-1][linelen-1]= 0;
  1460.     MemFree(lines);
  1461.     fLinebuf[kMaxLinebuf]= 0;
  1462.     return fLinebuf;
  1463. }
  1464.  
  1465.  
  1466.  
  1467. short DDrawZymeRow::GetHeight( Nlm_RecT& r, short row, long startitem, long stopitem)
  1468.     return DrawOrMeasure( false, r, row, startitem, stopitem);
  1469. }
  1470.  
  1471. void DDrawZymeRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  1472. {
  1473.     if (col) { startitem += col; } // ??? 
  1474.     (void) DrawOrMeasure( true, r, row, startitem, stopitem);
  1475. }
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481. /******** 
  1482. methods & fields for various draw objects:
  1483.   single-seq
  1484.   multi-seq  
  1485.     single-seq [+rezymes] [+complement] [+amino-trans] [+... others]
  1486.   multi-seq  [+?consensus] [+?? annotations of various kinds for mseq ] 
  1487.   
  1488.   fSeqsPerParag
  1489.   fSeqLinesPerParag
  1490.   fSpacersPerParag
  1491.   
  1492.   DRowDrawer* GetRowDrawer( atseq):
  1493.         Spacer, TopIndex, 
  1494.         SeqLine(s), ComplSeqLine,
  1495.          AA[1-3], CompAA[1-3], RestEnzyme
  1496.   
  1497.   make fRowsList [1..fLinesPerParag] of DRowDrawer objects...
  1498.   
  1499.   calcs:
  1500.     //linesPerParag = fSeqLinesPerParag + fSpacersPerParag
  1501.     atseq  = (row % fLinesPerParag)
  1502.         seqline= (row / fLinesPerParag) * seqsperparag;  
  1503.         startcol= seqline * fBasesPerLine;
  1504.         stopcol = startcol + fBasesPerLine;
  1505. *****/
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511. // class DSeqPrintView
  1512.  
  1513. class DSeqPrintView : public DTableView 
  1514. {
  1515. public:
  1516.     Boolean        fOneseq, fDoLeftName, fDoRightName, 
  1517.                         fDoTopIndex, fDoLeftIndex, fDoRightIndex; 
  1518.     Nlm_FonT    fNameFont, fNumFont, fBaseFont;
  1519.     short         fBaseWidth, fIndexWidth, fIndexWidthCnt, fNameWidth, fNameWidthCnt, 
  1520.                         fSeqsperparag, fExtrarows, fSeqLinesPerParag, fLinesPerParag, 
  1521.                         fTopPerparag, fBasesPerLine, fTenSpacer;
  1522.     long             fFirstBase, fNbases, fMaxbases, fSeqWidth;
  1523.     DSeqPrintDoc    * fDoc;
  1524.     DSeqList    * fSeqList;  
  1525.     DSequence * fSeq;
  1526.     DList            * fDrawRowList, * fStyles;
  1527.     DFile            * fFile;
  1528.     char            * fCommonbase, * fFirstcommon;
  1529.  
  1530.     //DCheckBox*        fLeftName, fRightName, fTopIndex, fLeftIndex, fRightIndex ;
  1531.     //DDlogTextView*        fStyleName, fStyleBase, fStyleNums; 
  1532.     
  1533.     DSeqPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  1534.                                  DSeqList* itsSeqList, long firstbase, long nbases,
  1535.                                  long pixwidth, long pixheight);
  1536.     virtual ~DSeqPrintView();
  1537.     virtual void Initialize();
  1538.  
  1539.     virtual void MakeDrawList();
  1540.     virtual void Draw();
  1541.     virtual void DrawRow(Nlm_RecT r, short row);
  1542.     virtual void IndexFromRow( short row, long& itemrow, long& seqline, long& startitem, long& stopitem);
  1543.     virtual void GetReadyToShow();
  1544.     virtual void DrawSideIndex( Nlm_RecT& aRect, long atBase, long leftBorder);
  1545.     virtual void WriteSideIndex( long atBase, long leftBorder);
  1546.     virtual void DrawName( Nlm_RecT& aRect, short rightBorder, char* name);
  1547.     virtual void WriteName( short rightBorder, char* name);
  1548.     virtual short GetExtraRows() { return fExtrarows; }
  1549.  
  1550.     virtual void WriteTo(DFile* aFile);
  1551.     virtual    void WriteRow(short row);
  1552. };
  1553.  
  1554.  
  1555.  
  1556. DSeqPrintView::DSeqPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  1557.                                  DSeqList* itsSeqList, long firstbase, long nbases,
  1558.                                  long pixwidth, long pixheight):
  1559.     DTableView( id, itsSuper, pixwidth, pixheight, 0, 0,  
  1560.                             Nlm_stdCharWidth, Nlm_stdLineHeight, true, true),
  1561.     fDoc(itsDocument), fSeqList(itsSeqList), fSeq(NULL), 
  1562.     fDrawRowList(NULL), fStyles(NULL),
  1563.     fCommonbase(NULL), fFirstcommon(NULL),
  1564.     fFirstBase(firstbase), fNbases(nbases), fMaxbases(nbases),
  1565.     fSeqLinesPerParag(kSeqLinesPerParag), fTopPerparag(2),
  1566.     fLinesPerParag(kSeqLinesPerParag+2), fSeqWidth(0),
  1567.     fBasesPerLine(DSeqPrintPrefs::gBasesPerLine), fExtrarows(0),
  1568.     fIndexWidth(kIndexWidth), fIndexWidthCnt(5),
  1569.     fNameWidth(kNameWidth), fNameWidthCnt(8)
  1570.  
  1571.     this->SetSlateBorder( false);
  1572.     this->SetResize( DView::relsuper, DView::relsuper);
  1573.     this->SetTableFont(gTextFont);
  1574.     fBaseWidth= BaseCharWidth();
  1575.     fOneseq= fSeqList->GetSize()<2; 
  1576.     
  1577.   fSeq= (DSequence*) fSeqList->At(0);
  1578.  
  1579.     Initialize();  
  1580. }
  1581.  
  1582.  
  1583. DSeqPrintView::~DSeqPrintView()
  1584. {    
  1585.     fDrawRowList= FreeListIfObject(fDrawRowList);
  1586.     fStyles= FreeListIfObject(fStyles);
  1587.     MemFree( fCommonbase);
  1588.     MemFree( fFirstcommon);
  1589. }
  1590.  
  1591. void DSeqPrintView::Initialize()
  1592.     fDoTopIndex= DSeqPrintPrefs::gIndexTop;
  1593.     fDoLeftIndex= DSeqPrintPrefs::gIndexLeft; 
  1594.     fDoRightIndex= DSeqPrintPrefs::gIndexRight;  
  1595.     fDoLeftName= DSeqPrintPrefs::gNameLeft; 
  1596.     fDoRightName= DSeqPrintPrefs::gNameRight;
  1597.     
  1598.     fNameFont = DSeqPrintPrefs::gNameFont;
  1599.     fNumFont  = DSeqPrintPrefs::gIndexFont;
  1600.     fBaseFont = DSeqPrintPrefs::gBaseFont;
  1601. }
  1602.  
  1603.  
  1604. void DSeqPrintView::MakeDrawList()
  1605. {
  1606.     short i, n;
  1607.     fDrawRowList= FreeListIfObject(fDrawRowList);
  1608.     fDrawRowList= new DList(NULL, DList::kDeleteObjects);
  1609.     fDrawRowList->InsertLast( new DDrawSpacer());
  1610.     if (fDoTopIndex) 
  1611.         fDrawRowList->InsertLast( new DDrawIndexRow(fNumFont,fBaseWidth));
  1612.  
  1613.     ulong * colors;
  1614.     //if (!fDoc->fUseColor) colors= NULL;
  1615.     if (!DSeqPrintPrefs::gColored) colors= NULL;
  1616.     else if (fSeq->Kind() == DSequence::kAmino) colors= DBaseColors::gAAcolors;
  1617.     else colors= DBaseColors::gNAcolors;
  1618.  
  1619.     fStyles= FreeListIfObject(fStyles);
  1620.     fStyles= new DList(NULL,DList::kDeleteObjects);
  1621.     n= DStyleTable::fStyles->GetSize();
  1622.     for (i=0; i<n; i++) {
  1623.         DSeqStyle    *    astyle= (DSeqStyle*) DStyleTable::fStyles->At(i);
  1624.         astyle= (DSeqStyle*) astyle->Clone();
  1625.         fStyles->InsertLast( astyle);
  1626.         }
  1627.         
  1628.     if (!fOneseq) {
  1629.         fCommonbase= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, fFirstcommon);
  1630.         for (i= 0; i < fSeqLinesPerParag; i++) {
  1631.           DDrawManySeqRow* dd= new DDrawManySeqRow( fBaseFont, this, fSeqList, i, 
  1632.                   fStyles, colors, fCommonbase, fFirstcommon);
  1633.           fDrawRowList->InsertLast(dd);
  1634.             }
  1635.         }
  1636.     else {
  1637.       for (i= 0; i < fSeqLinesPerParag; i++) { 
  1638.             DDrawSeqRow* dd= new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors);
  1639.           fDrawRowList->InsertLast( dd);
  1640.            }    
  1641.     }
  1642. }
  1643.  
  1644.  
  1645. void DSeqPrintView::GetReadyToShow()
  1646. {
  1647.     char nums[50];
  1648.     long diff, nrows, nbases= 0;
  1649.  
  1650.     if (fOneseq)    {
  1651.         fSeqsperparag = fSeqLinesPerParag;
  1652.         }
  1653.   else {
  1654.         fSeqLinesPerParag= fSeqList->GetSize(); //?? or leave to subclasses?
  1655.         fSeqsperparag = 1;
  1656.         }
  1657.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  1658.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  1659.     fLinesPerParag += fSeqLinesPerParag;
  1660.  
  1661. #if 1
  1662.     if (fNbases) nbases= fNbases;
  1663.     else
  1664. #endif
  1665.     if (fSeqList) {
  1666.         short i, nseq= fSeqList->GetSize();
  1667.         for (i=0; i<nseq; i++) {
  1668.             DSequence* aseq= fSeqList->SeqAt(i);
  1669.             nbases= Max(nbases, aseq->LengthF());
  1670.             }
  1671.         fNbases= nbases; 
  1672.         }
  1673.     else if (fSeq) { nbases= fSeq->LengthF(); fNbases= nbases; }
  1674.     fMaxbases= nbases;
  1675.     
  1676.     // assume port is set??
  1677.     SelectFont();
  1678.     if (fNameFont) Nlm_SelectFont(fNameFont);  
  1679.     fNameWidth= 5 + Nlm_StringWidth("Sequence");
  1680.     fNameWidthCnt= 8;
  1681.     
  1682.     if (fNumFont) Nlm_SelectFont(fNumFont);  
  1683.     sprintf( nums, "%d", fMaxbases);
  1684.     fIndexWidthCnt= StrLen(nums);
  1685.     fIndexWidth= 5 + fIndexWidthCnt * Nlm_CharWidth('0');
  1686.  
  1687.     if (fBaseFont) Nlm_SelectFont(fBaseFont);  
  1688.     fBaseWidth= BaseCharWidth();  
  1689.     
  1690.     short ncols= fBasesPerLine + 4;
  1691.     if (ncols > GetMaxCols()) ChangeColSize( -1, ncols-GetMaxCols());
  1692.  
  1693.   MakeDrawList();
  1694.  
  1695.     SetItemWidth( 0, 1, (fDoLeftName)?fNameWidth:1);
  1696.     SetItemWidth( 1, 1, (fDoLeftIndex)?fIndexWidth:1);
  1697.     SetItemWidth( 2, fBasesPerLine, fBaseWidth);  
  1698.   fSeqWidth= fBasesPerLine * fBaseWidth; //!?!?
  1699.     SetItemWidth( fBasesPerLine+2, 1, (fDoRightIndex)?fIndexWidth:1);
  1700.     SetItemWidth( fBasesPerLine+3, 1, (fDoRightName)?fNameWidth:1);
  1701.  
  1702.     nrows= 1 + (nbases / fBasesPerLine) / fSeqsperparag;
  1703.     nrows *= fLinesPerParag;
  1704.     nrows += GetExtraRows();
  1705.     diff  = Max( 3, nrows) - GetMaxRows();
  1706.     ChangeRowSize( -1, diff);  // -1 prevents redraw..else use fMaxRows    
  1707.  
  1708.     Nlm_RecT  r;
  1709.     ViewRect(r);
  1710.     nrows= GetMaxRows();  
  1711.     for (long irow=0; irow<nrows; irow++) {
  1712.         long itemrow, seqline, startitem, stopitem;
  1713.         IndexFromRow( irow, itemrow, seqline, startitem, stopitem);
  1714.         DDrawMapRow* drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  1715.         SetItemHeight( irow, 1, 
  1716.             (drawer) ? drawer->GetHeight(r, irow, startitem, stopitem) : Nlm_stdLineHeight);
  1717.         }
  1718.         
  1719. }
  1720.  
  1721.  
  1722. void DSeqPrintView::DrawSideIndex( Nlm_RecT& aRect, long index, long leftBorder)
  1723. {
  1724.     if (index != DDrawMapRow::kNoIndex) {
  1725.         char nums[128];
  1726.         Nlm_SelectFont(fNumFont); 
  1727.         sprintf(nums, "%d", index); // or char* nump= ltoa(index);
  1728.         short atx= aRect.right - leftBorder - Nlm_StringWidth(nums);
  1729.         Nlm_MoveTo( atx, aRect.bottom - kFontDescent);
  1730.         Nlm_PaintString(nums);
  1731.         }
  1732. }
  1733.  
  1734. void DSeqPrintView::WriteSideIndex( long index, long leftBorder)
  1735. {
  1736.     char fmt[30];
  1737.     if (index != DDrawMapRow::kNoIndex) {
  1738.         if (leftBorder > 0) sprintf( fmt, " %%%dd",fIndexWidthCnt);
  1739.         else sprintf( fmt, " %%-%dd",fIndexWidthCnt);
  1740.         fprintf( fFile->fFile, fmt, index);
  1741.         }
  1742.     else {
  1743.         sprintf( fmt, " %%%ds",fIndexWidthCnt);
  1744.         fprintf( fFile->fFile, fmt, "");
  1745.         }
  1746. }
  1747.  
  1748. void DSeqPrintView::DrawName( Nlm_RecT& aRect, short rightBorder, char* name)
  1749. {
  1750.     if (name) {
  1751.         Nlm_SelectFont(fNameFont); 
  1752.         short ht= 2 * Nlm_stdLineHeight;
  1753.         if (aRect.bottom - aRect.top > ht)
  1754.             Nlm_MoveTo( aRect.left + rightBorder, aRect.top + ht);
  1755.         else     
  1756.             Nlm_MoveTo( aRect.left + rightBorder, aRect.bottom - kFontDescent);
  1757.         Nlm_PaintString( name);
  1758.         } 
  1759. }
  1760.  
  1761. void DSeqPrintView::WriteName( short rightBorder, char* name)
  1762. {
  1763.     char fmt[30];
  1764.     if (rightBorder > 0) sprintf( fmt, "  %%-%ds",fNameWidthCnt);
  1765.     else sprintf( fmt, "%%%ds ",fNameWidthCnt);
  1766.     if (!name) name= "";
  1767.     fprintf( fFile->fFile, fmt, name);
  1768. }
  1769.  
  1770.  
  1771. void DSeqPrintView::IndexFromRow( short row, long& itemrow, long& seqline, long& startitem, long& stopitem)
  1772. {
  1773.     itemrow    = (row % fLinesPerParag);  
  1774.     seqline = (row / fLinesPerParag) * fSeqsperparag;   
  1775.     if (fOneseq) seqline += Max( 0, itemrow - fTopPerparag);
  1776. #if 1
  1777.     startitem = fFirstBase + seqline * fBasesPerLine;
  1778.     stopitem  = Min(startitem + fBasesPerLine, fFirstBase+fNbases);
  1779.     if (startitem>stopitem) { startitem= stopitem; }
  1780. #else
  1781.     startitem = seqline * fBasesPerLine;
  1782.     stopitem  = startitem + fBasesPerLine;
  1783. #endif
  1784. }
  1785.  
  1786.  
  1787. void DSeqPrintView::Draw()
  1788. {
  1789. #if MASKS
  1790.             // !! toprowbases should be just CONSENSUS/Common bases, not rare ones
  1791. #if 0
  1792.     short minCommonPerCent= 70;
  1793.     char * commons= FindCommonBases( minCommonPerCent); 
  1794.      // ^^ OOPs, this is made new for each draw .. bad news
  1795.     DStyleTable::StartDraw( commons, StrLen(commons));
  1796. #else
  1797.     //DSequence* aSeq= fSeqList->SeqAt(0);
  1798.     DStyleTable::StartDraw( fSeq->Bases(), fSeq->LengthF());
  1799. #endif
  1800. #endif
  1801.  
  1802.     DTableView::Draw();
  1803.     
  1804. #if MASKS
  1805.     DStyleTable::EndDraw();
  1806. #endif
  1807. }
  1808.  
  1809. void DSeqPrintView::DrawRow(Nlm_RecT r, short row)
  1810. {
  1811.     long             itemrow, seqline, startitem, stopitem;
  1812.     short         col, ncols;
  1813.     Nlm_RecT    r1, viewr;
  1814.     Nlm_RegioN     cliprgn;
  1815.     DDrawMapRow * drawer;
  1816.     
  1817.     col = GetLeft(); 
  1818.     if (fWidths && col <= fMaxCols) r.right= r.left + fWidths[col];
  1819.     else r.right= r.left + fItemWidth;
  1820.     ViewRect( viewr);
  1821.  
  1822.     IndexFromRow( row, itemrow, seqline, startitem, stopitem);
  1823.   cliprgn= Nlm_CreateRgn();
  1824.     drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  1825.   
  1826.     if (drawer) {
  1827.         drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1828.         while (r.left < fRect.right && col < fMaxCols) {
  1829.             if (col < 2 || col > fBasesPerLine+1) {
  1830.                         // do name & index borders
  1831.                 ncols= 1;
  1832.                 if (col == 0 && !fDoLeftName && drawer->DoLeftName()) // special case, fiddle w/ clip rgn...
  1833.                     { r.right += fItemWidth; }
  1834.                 (void) Nlm_SectRect( &r, &viewr, &r1);
  1835.                 RectRgn( cliprgn, &r1);  
  1836.                 Nlm_SectRgn( cliprgn, Nlm_updateRgn, cliprgn);
  1837.                 if ( !Nlm_EmptyRgn( cliprgn)) {
  1838.                     Nlm_ClipRgn(cliprgn);
  1839.                     r1= r;
  1840.                     if (col == 0) {
  1841.                         if (fDoLeftName || drawer->DoLeftName()) DrawName( r1, 0, drawer->GetName(row));
  1842.                         }
  1843.                     else if (col == 1) {
  1844.                         if (fDoLeftIndex) DrawSideIndex( r1, drawer->GetIndex(startitem), kNucBorder);
  1845.                         }
  1846.                     else if (col == fBasesPerLine+2) {
  1847.                         if (fDoRightIndex) DrawSideIndex( r1,  drawer->GetIndex(stopitem), 0);
  1848.                         }
  1849.                     else if (col == fBasesPerLine+3) {
  1850.                         if (fDoRightName) DrawName( r1, kNucBorder, drawer->GetName(row));        
  1851.                         }    
  1852.                     }
  1853.                 }
  1854.                 
  1855.             else if (col < fBasesPerLine+2) {
  1856.                 r.right= r.left + fSeqWidth;
  1857.                 ncols= fBasesPerLine; //stopitem - startitem;
  1858.                 (void) Nlm_SectRect( &r, &viewr, &r1);
  1859.                 RectRgn( cliprgn, &r1);  
  1860.                 Nlm_SectRgn( cliprgn, Nlm_updateRgn, cliprgn);
  1861.                 if ( !Nlm_EmptyRgn( cliprgn)) {
  1862.                     r1= r;
  1863.                     //Nlm_ClipRgn(cliprgn);
  1864.                     //drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1865.                     drawer->Clip( r1, row, startitem, stopitem, viewr, cliprgn);
  1866.                     drawer->Draw( r1, row, col-2, startitem, stopitem);
  1867.                     }
  1868.                 }
  1869.         
  1870.           col += ncols;
  1871.             r.left= r.right;
  1872.             if (fWidths) r.right += fWidths[col];
  1873.             else r.right += fItemWidth;
  1874.             }
  1875.         }
  1876.     //Nlm_ClipRgn(Nlm_updateRgn);
  1877.     fColsDrawn= col - GetLeft();
  1878.     Nlm_ResetClip();
  1879.     Nlm_DestroyRgn(cliprgn);
  1880. }
  1881.  
  1882.  
  1883. void DSeqPrintView::WriteTo(DFile* aFile)
  1884. {
  1885.     if (aFile) {
  1886.         long irow, nrows;
  1887.         fFile= aFile;
  1888.         fFile->Open("a");
  1889.         nrows= GetMaxRows();  
  1890.         for (irow=0; irow<nrows; irow++) WriteRow( irow);
  1891.         fFile->Close();
  1892.         }
  1893. }
  1894.  
  1895. void DSeqPrintView::WriteRow(short row)
  1896. {
  1897.     long             itemrow, seqline, startitem, stopitem;
  1898.     short         col, ncols;
  1899.     DDrawMapRow * drawer;
  1900.     char * newline, * atline;
  1901.     
  1902.     IndexFromRow( row, itemrow, seqline, startitem, stopitem);
  1903.     drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  1904.     if (!drawer) return;
  1905.     drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1906.  
  1907.     atline= (char*) drawer->Write( row, 0, startitem, stopitem);
  1908.     while (atline) {
  1909.         newline= StrChr(atline, '\n');
  1910.         if (newline) *newline++= 0; // risky: (const char*) drawer->Write()
  1911.         
  1912.         for (col=0, ncols=1; col<fMaxCols; col += ncols) {
  1913.             if (col < 2 || col > fBasesPerLine+1) {
  1914.                         // do name & index borders
  1915.                 ncols= 1;
  1916.                 if (col == 0) {
  1917.                     if (fDoLeftName || drawer->DoLeftName()) WriteName(  0, drawer->GetName(row));
  1918.                     }
  1919.                 else if (col == 1) {
  1920.                     if (fDoLeftIndex) WriteSideIndex( drawer->GetIndex(startitem), kNucBorder);
  1921.                     }
  1922.                 else if (col == fBasesPerLine+2) {
  1923.                     if (fDoRightIndex) WriteSideIndex(  drawer->GetIndex(stopitem), 0);
  1924.                     }
  1925.                 else if (col == fBasesPerLine+3) {
  1926.                     if (fDoRightName) WriteName(  kNucBorder, drawer->GetName(row));        
  1927.                     }    
  1928.                 }
  1929.             else {
  1930.                 ncols= fBasesPerLine; 
  1931.                 fFile->WriteLine( " ", false);
  1932.                 fFile->WriteLine( atline, false);
  1933.                 }
  1934.             }
  1935.             
  1936.         atline= newline;
  1937.         fFile->WriteLine("\n");
  1938.         }
  1939. }
  1940.  
  1941.  
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949. // class DSeqPrintDoc
  1950.  
  1951.  
  1952. Nlm_RecT DSeqPrintDoc::fgPrWinRect = { 0, 0, 0, 0 };
  1953.  
  1954. DSeqPrintDoc::DSeqPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  1955.         DWindow( kSeqPrintDoc, gApplication),
  1956.         fView(NULL),  
  1957.         fSeqList(itsSeqList),
  1958.         fFirstBase(firstbase), fNbases(nbases),
  1959.         //fHeadline(NULL), fFormatPop(NULL),
  1960.         //fLockButton(NULL), fColorButton(NULL), fMonoButton(NULL),
  1961.         fColorCheck(NULL), fLockCheck(NULL), 
  1962.         fUseColor(itsDoc->fUseColor)
  1963.     short width= -1, height= -1, left= -10, top= -20; // default window loc
  1964.     if (id != 0) fId= id;
  1965.     
  1966.     //gTextFont = Nlm_GetFont( "Courier", 10, false, false, false, "Fixed");
  1967.     //if (gTextFont == NULL) gTextFont= Nlm_programFont;
  1968.  
  1969.     if (!Nlm_EmptyRect(&fgPrWinRect))  {
  1970.         left= MAX(20,fgPrWinRect.left);
  1971.         top = MAX(40,fgPrWinRect.top);
  1972.         }
  1973.     
  1974.     char * winname= NULL;
  1975.     this->InitWindow( document, width, height, left, top); //, winname); 
  1976.  
  1977.     DSequence * aSeq;
  1978.     char title[256];
  1979.     if (!fSeqList) {
  1980.         fSeqList= new DSeqList();  
  1981.         fSeqList->AddNewSeq();    // install 1 blank seq for new doc
  1982.         aSeq= NULL;
  1983.         }
  1984.     else {
  1985.       aSeq= (DSequence*) fSeqList->At(0);
  1986.         }
  1987.     if (aSeq)  
  1988.         StrCpy(title, aSeq->Name());
  1989.     else
  1990.         itsDoc->GetTitle( title, sizeof(title)); 
  1991.     StrCat( title, " Print");
  1992.     SetTitle( title);
  1993. }
  1994.  
  1995.  
  1996. DSeqPrintDoc::~DSeqPrintDoc()
  1997. {
  1998.     if (fSeqList) { 
  1999.         // we don't own DSeq objects in this list !!
  2000.         //fSeqList->FreeAllObjects(); 
  2001.         fSeqList->suicide(); 
  2002.         }
  2003. }
  2004.  
  2005.  
  2006. void DSeqPrintDoc::MakeGlobalsCurrent()
  2007. {
  2008.     ViewRect( fViewrect); // get current rect...
  2009.     if (!Nlm_EmptyRect(&fViewrect)) fgPrWinRect= fViewrect;  
  2010.     //fgUseColor= fColorCheck->GetStatus();
  2011. }
  2012.  
  2013. void DSeqPrintDoc::Close()
  2014. {
  2015.     MakeGlobalsCurrent();
  2016.     DWindow::Close();
  2017. }
  2018.  
  2019. void DSeqPrintDoc::ResizeWin()
  2020. {
  2021.     DWindow::ResizeWin();
  2022.     MakeGlobalsCurrent();
  2023. }
  2024.  
  2025.  
  2026. // static
  2027. void DSeqPrintDoc::GetGlobals()
  2028. {
  2029.  
  2030.     //char* onoffs= (fgUseColor) ? "1" : "0";
  2031.     //fgUseColor= gApplication->GetPrefVal( "fgUseColor", "windows", onoffs);
  2032.     {
  2033.     char* srect = gApplication->GetPref( "fgPrWinRect", "windows", "30 40 450 220");
  2034. #if 1
  2035.         // sscanf is failing on Mac/codewar !! used to work
  2036.     if (srect) {
  2037.         char* cp= srect;
  2038.         while (*cp && isspace(*cp)) cp++;
  2039.         fgPrWinRect.left= atoi( cp);
  2040.         
  2041.         while (*cp && !isspace(*cp)) cp++;
  2042.         while (*cp && isspace(*cp)) cp++;
  2043.         fgPrWinRect.top= atoi( cp);
  2044.         
  2045.         while (*cp && !isspace(*cp)) cp++;
  2046.         while (*cp && isspace(*cp)) cp++;
  2047.         fgPrWinRect.right= atoi( cp);
  2048.         
  2049.         while (*cp && !isspace(*cp)) cp++;
  2050.         while (*cp && isspace(*cp)) cp++;
  2051.         fgPrWinRect.bottom= atoi( cp);
  2052.         }
  2053. #else
  2054.         if (srect) sscanf( srect, "%d%d%d%d", &fgPrWinRect.left, &fgPrWinRect.top, 
  2055.                                                 &fgPrWinRect.right, &fgPrWinRect.bottom);
  2056. #endif
  2057.         Nlm_MemFree(srect);
  2058.     }
  2059. }
  2060.  
  2061. // static
  2062. void DSeqPrintDoc::SaveGlobals()
  2063. {
  2064.     //gApplication->SetPref( (int) fgUseColor, "fgUseColor","windows");
  2065.     if (!Nlm_EmptyRect(&fgPrWinRect)) {
  2066.         char  srect[128];
  2067.         sprintf( srect, "%d %d %d %d", fgPrWinRect.left, fgPrWinRect.top, 
  2068.                                                         fgPrWinRect.right, fgPrWinRect.bottom);
  2069.         gApplication->SetPref( srect, "fgPrWinRect", "windows");
  2070.         }
  2071. }
  2072.  
  2073.  
  2074. void DSeqPrintDoc::Open()
  2075. {
  2076.     DView*     super;
  2077.     short width, height;
  2078.     Nlm_PoinT        nps;
  2079.     
  2080.     //if (!fSeqList) fSeqList= new DSeqList();
  2081.     if (!fView) {
  2082.         super= this;
  2083.     
  2084.         width= 450; height= 350;
  2085.         super->GetNextPosition( &nps);
  2086.         width = MAX( 40, fgPrWinRect.right - fgPrWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  2087.         height= MAX( 60, fgPrWinRect.bottom - fgPrWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  2088.         fView= new DSeqPrintView(0,super,this,fSeqList,fFirstBase,fNbases,width,height);
  2089.         }
  2090.  
  2091.     fSaveHandler= this;  
  2092.     fPrintHandler= this;
  2093.     
  2094.     this->Select(); // for motif
  2095.     this->CalcWindowSize();
  2096.     fView->GetReadyToShow();
  2097.     
  2098.     DWindow::Open();
  2099. }
  2100.  
  2101.  
  2102.  
  2103.  
  2104. void DSeqPrintDoc::WriteTo(DFile* aFile)  
  2105. {
  2106.         // offer user choice of Text or PICT (or other? - PS) output
  2107.         // need popup choice in save-as dialog...
  2108.     if (gKeys->shift())
  2109.         fView->WriteTo( aFile); // TEXT
  2110.     else
  2111.         fView->WriteToPICT( aFile); // PICT
  2112. }
  2113.  
  2114.  
  2115. void DSeqPrintDoc::Print()  
  2116. {
  2117.     fView->Print();
  2118. }
  2119.  
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131. // class DAlnPrintView
  2132.  
  2133. class DAlnPrintView : public DSeqPrintView {
  2134. public:
  2135.  
  2136.     DAlnPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  2137.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight);
  2138. };
  2139.  
  2140. DAlnPrintView::DAlnPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  2141.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight):
  2142.         DSeqPrintView( id, itsSuper, itsDocument, itsSeqList, firstbase, nbases, pixwidth, pixheight)
  2143.     fSeqLinesPerParag= fSeqList->GetSize();
  2144. }
  2145.  
  2146. // class DAlnPrintDoc
  2147.  
  2148. DAlnPrintDoc::DAlnPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  2149.     DSeqPrintDoc( id, itsDoc, itsSeqList, firstbase, nbases)
  2150. {
  2151.  
  2152.     short width= 450, height= 350;
  2153.     //super->GetNextPosition( &nps);
  2154.     //width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  2155.     //height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  2156.     fView= new DAlnPrintView(0,this,this,fSeqList,fFirstBase,fNbases,width,height);
  2157.  
  2158.     char title[256];
  2159.     itsDoc->GetTitle( title, sizeof(title)); 
  2160.     StrCat( title, " Print");
  2161.     SetTitle( title);
  2162. }
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172. // class DREMapPrintView
  2173.  
  2174. class DREMapPrintView : public DSeqPrintView {
  2175. public:
  2176.     Boolean fDoAAline[6];
  2177.     Boolean fDoSeqLine,fDoMidIndex,fDoCoseqLine,fDoZymeLine;
  2178.     short        fMaxseqrow;
  2179.     
  2180.     DREMapPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  2181.                     DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight);
  2182.     virtual void Initialize();
  2183.     virtual void MakeDrawList();
  2184.     virtual void SetScrollPage();
  2185.     virtual void IndexFromRow( short row, long& itemrow, long& seqline, long& startitem, long& stopitem);
  2186. };
  2187.  
  2188.  
  2189.  
  2190. DREMapPrintView::DREMapPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  2191.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight):
  2192.     DSeqPrintView( id, itsSuper, itsDocument, itsSeqList, firstbase, 
  2193.                             nbases, pixwidth, pixheight)
  2194.     Initialize();
  2195. }
  2196.  
  2197. void DREMapPrintView::IndexFromRow( short row, long& itemrow, long& seqline, long& startitem, long& stopitem)
  2198. {
  2199.         // !! modify itemrow to return drawer item row for tables after all of sequence as been drawn
  2200.   if (row > fMaxseqrow) {
  2201. #if 1
  2202.         short i, n = fDrawRowList->GetSize();
  2203.         itemrow= fLinesPerParag;
  2204.     seqline= row - fMaxseqrow - 2; //??
  2205.         for (i= fLinesPerParag; i<n; i++) {
  2206.             DDrawMapRow* drawer= (DDrawMapRow*) fDrawRowList->At(i);
  2207.             if (drawer && 
  2208.                   row >= drawer->fRowOffset && row < drawer->fRowOffset + drawer->fLinecount) { 
  2209.                   itemrow= i;
  2210.                   seqline= row - drawer->fRowOffset; //??
  2211.                   break; 
  2212.                     }
  2213.             }
  2214. #else
  2215.     itemrow= fLinesPerParag; // need to adjust this for each spacer, etc...
  2216.       if (row > fMaxseqrow + 1) itemrow++;
  2217.     seqline= row - fMaxseqrow - 2; //??
  2218. #endif
  2219.         startitem = seqline;
  2220.         stopitem  = startitem+1; //??
  2221.       }
  2222.   else {
  2223.         itemrow    = (row % fLinesPerParag);  
  2224.         seqline = (row / fLinesPerParag) * fSeqsperparag;   
  2225.         if (fOneseq) seqline += Max( 0, itemrow - fTopPerparag);
  2226. #if 1
  2227.         startitem = fFirstBase + seqline * fBasesPerLine;
  2228.         stopitem  = Min(startitem + fBasesPerLine, fFirstBase+fNbases);
  2229. #else
  2230.         startitem = seqline * fBasesPerLine;
  2231.         stopitem  = startitem + fBasesPerLine;
  2232. #endif
  2233.         }
  2234. }
  2235.  
  2236. void DREMapPrintView::Initialize()
  2237. {
  2238.     DSeqPrintView::Initialize();
  2239.  
  2240.     fSeqLinesPerParag= 1;
  2241.     fOneseq= false;
  2242.     fDoMidIndex= fDoTopIndex;
  2243.     fDoTopIndex= false;
  2244.     fDoSeqLine= true;
  2245.     fDoCoseqLine= DSeqPrintPrefs::gShowComplement;
  2246.     fDoZymeLine= true;
  2247.   
  2248.     fDoAAline[0]= DSeqPrintPrefs::gShowAA1;
  2249.     fDoAAline[1]= DSeqPrintPrefs::gShowAA2;
  2250.     fDoAAline[2]= DSeqPrintPrefs::gShowAA3;
  2251.     fDoAAline[3]= DSeqPrintPrefs::gShowCompAA1;
  2252.     fDoAAline[4]= DSeqPrintPrefs::gShowCompAA2;
  2253.     fDoAAline[5]= DSeqPrintPrefs::gShowCompAA3;    
  2254.     
  2255. }
  2256.  
  2257. void DREMapPrintView::SetScrollPage()
  2258. {
  2259.     fItemHeight= Nlm_stdLineHeight;
  2260.     DTableView::SetScrollPage();
  2261. }
  2262.  
  2263. void DREMapPrintView::MakeDrawList()
  2264. {
  2265.     short i, n;
  2266.     ulong * colors = NULL;
  2267.     DDrawZymeRow * zymerow = NULL;
  2268.     DSequence* coseq = NULL;
  2269.     Boolean anyamino;
  2270.     
  2271.     fDrawRowList= FreeListIfObject(fDrawRowList);
  2272.     fDrawRowList= new DList(NULL, DList::kDeleteObjects);
  2273.     fDrawRowList->InsertLast(new DDrawSpacer());
  2274.     if (fDoTopIndex) 
  2275.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth));
  2276.  
  2277.     if (fDoZymeLine) {
  2278.         fSeq->SetSelection(fFirstBase, fNbases);  // !? zyme map for only selected section
  2279.         zymerow= new DDrawZymeRow( fNameFont, fSeq);
  2280.         if (zymerow) {
  2281.             if (!zymerow->fGoodMap) { delete zymerow; zymerow= NULL; }
  2282.             else coseq= zymerow->fCoSeq;
  2283.             }
  2284.         }
  2285.     else if (fDoCoseqLine) {
  2286.         fSeq->SetSelection(0,0); // for Complement...
  2287.         coseq= fSeq->Complement();
  2288.         }
  2289.     
  2290.     anyamino= false;
  2291.     for (i=0; i<6; i++) if (fDoAAline[i]) anyamino= true;
  2292.  
  2293.     fStyles= FreeListIfObject(fStyles);
  2294.     fStyles= new DList(NULL,DList::kDeleteObjects);
  2295.     n= DStyleTable::fStyles->GetSize();
  2296.     for (i=0; i<n; i++) fStyles->InsertLast( DStyleTable::fStyles->At(i));
  2297.     
  2298. #if 1
  2299.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  2300.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  2301.     if (fDoSeqLine)
  2302.         fDrawRowList->InsertLast( 
  2303.             new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors));
  2304.     if (fDoSeqLine) { fLinesPerParag++;  }
  2305.     if (fDoMidIndex) 
  2306.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  2307.     if (fDoMidIndex) { fLinesPerParag++;  }
  2308.     if (fDoCoseqLine && coseq)
  2309.         fDrawRowList->InsertLast( 
  2310.             new DDrawSeqRow( fBaseFont, this, coseq, fStyles, "compl", colors));
  2311.     if (fDoCoseqLine && coseq) { fLinesPerParag++;}
  2312.     if (fDoZymeLine && zymerow)
  2313.         fDrawRowList->InsertLast( zymerow);
  2314.     if (fDoZymeLine && zymerow) { fLinesPerParag++; }
  2315.     if (anyamino)
  2316.         fDrawRowList->InsertLast(new DDrawSpacer()); fLinesPerParag++;
  2317.         
  2318.     for (i= 0; i<3; i++) if (fDoAAline[i])
  2319.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, fSeq, i));
  2320.     for (i= 0; i<3; i++) if (fDoAAline[i]) { fLinesPerParag++;  }
  2321.     if (fDoMidIndex) 
  2322.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  2323.     if (fDoMidIndex) { fLinesPerParag++;  }
  2324.     for (i= 3; i<6; i++) if (fDoAAline[i] && coseq)
  2325.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, coseq, i));
  2326.     for (i= 3; i<6; i++) if (fDoAAline[i]) fLinesPerParag++;
  2327.  
  2328.     fDrawRowList->InsertLast(new DDrawSpacer()); fLinesPerParag++;
  2329.     
  2330. #else
  2331.     for (i= 0; i<3; i++) if (fDoAAline[i])
  2332.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, fSeq, i));
  2333.     if (fDoSeqLine)
  2334.         fDrawRowList->InsertLast( 
  2335.             new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors));
  2336.     if (fDoMidIndex) 
  2337.         fDrawRowList->InsertLast(new DDrawIndexRow(fNumFont,fBaseWidth,false));
  2338.     if (fDoMidIndex) { fLinesPerParag++;  }
  2339.     if (fDoCoseqLine && coseq)
  2340.         fDrawRowList->InsertLast( 
  2341.             new DDrawSeqRow( fBaseFont, this, coseq, fStyles, "compl", colors));
  2342.     for (i= 3; i<6; i++) if (fDoAAline[i] && coseq)
  2343.         fDrawRowList->InsertLast( new DDrawAminoRow( fBaseFont, coseq, i));
  2344.     if (fDoZymeLine && zymerow)
  2345.         fDrawRowList->InsertLast( zymerow);
  2346.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  2347.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  2348.     for (i= 0; i<3; i++) if (fDoAAline[i]) { fLinesPerParag++; fTopPerparag++; }
  2349.     if (fDoSeqLine) { fLinesPerParag++;  }
  2350.     if (fDoCoseqLine && coseq) { fLinesPerParag++;}
  2351.     for (i= 3; i<6; i++) if (fDoAAline[i]) fLinesPerParag++;
  2352.     if (fDoZymeLine) { fLinesPerParag++; }
  2353. #endif
  2354.  
  2355.     fMaxseqrow= 1 + (fMaxbases / fBasesPerLine);
  2356.     fMaxseqrow *= fLinesPerParag;
  2357.     if (zymerow && DSeqPrintPrefs::gShowCutpoints) {
  2358.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  2359.         DDrawZymeCutTable* ztab= new DDrawZymeCutTable( gTextFont/*fNumFont*/,  
  2360.                                                                     zymerow->fREMap, fMaxseqrow+fExtrarows);  
  2361.         fDrawRowList->InsertLast( ztab);  
  2362.     fExtrarows += ztab->fLinecount + 1;
  2363.     }
  2364.     if (zymerow && DSeqPrintPrefs::gShowAllZymes) {
  2365.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  2366.         DDrawAllZymeTable* ztab= new DDrawAllZymeTable( gTextFont, zymerow->fREMap, 
  2367.                                                                         fMaxseqrow+fExtrarows);  
  2368.         fDrawRowList->InsertLast( ztab);  
  2369.     fExtrarows += ztab->fLinecount + 1;
  2370.     }
  2371.     if (zymerow && DSeqPrintPrefs::gShowNoncutters) {
  2372.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  2373.         DDrawNocutZymeTable* ztab= new DDrawNocutZymeTable( gTextFont, zymerow->fREMap, 
  2374.                                                                         fMaxseqrow+fExtrarows);  
  2375.         fDrawRowList->InsertLast( ztab);  
  2376.     fExtrarows += ztab->fLinecount + 1;
  2377.     }
  2378.     if (zymerow && DSeqPrintPrefs::gShowExcludedCutters) {
  2379.         fDrawRowList->InsertLast(new DDrawSpacer()); fExtrarows++;
  2380.         DDrawNocutZymeTable* ztab= new DDrawNocutZymeTable( gTextFont, zymerow->fREMap, 
  2381.                                                                         fMaxseqrow+fExtrarows, 
  2382.                                                                         DSeqPrintPrefs::gREMinCuts,
  2383.                                                                         DSeqPrintPrefs::gREMaxCuts);  
  2384.         fDrawRowList->InsertLast( ztab);  
  2385.     fExtrarows += ztab->fLinecount + 1;
  2386.     }
  2387.      
  2388. }
  2389.  
  2390.  
  2391.  
  2392. // class DREMapPrintDoc
  2393.  
  2394. DREMapPrintDoc::DREMapPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  2395.     DSeqPrintDoc( id, itsDoc, itsSeqList, firstbase, nbases)
  2396. {
  2397.     short width= 450, height= 350;
  2398.     //super->GetNextPosition( &nps);
  2399.     //width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  2400.     //height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  2401.     fView= new DREMapPrintView(0,this,this,fSeqList,fFirstBase,fNbases,width,height);
  2402.  
  2403.     char title[256];
  2404.     DSequence * aSeq= (DSequence*) fSeqList->At(0);
  2405.     if (aSeq)  
  2406.         StrCpy(title, aSeq->Name());
  2407.     else
  2408.         itsDoc->GetTitle( title, sizeof(title)); 
  2409.     StrCat( title, " Restr. Map");
  2410.     SetTitle( title);
  2411. }
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424. //class DSeqPrintPrefs : public DWindow 
  2425.  
  2426.  
  2427.  
  2428. DSeqPrintPrefs::DSeqPrintPrefs() :
  2429.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqPrint prefs", kDontFreeOnClose),
  2430.     fNameFontMenu(NULL), fBaseFontMenu(NULL),  fIndexFontMenu(NULL),
  2431.     fNameStyleMenu(NULL), fBaseStyleMenu(NULL),  fIndexStyleMenu(NULL),
  2432.     fNameSizeSw(NULL), fBaseSizeSw(NULL),  fIndexSizeSw(NULL),
  2433.     fREMinCuts(NULL),  fREMaxCuts(NULL), fBasePerLine(NULL),
  2434.     fNeedSave(false)
  2435. {    
  2436. }
  2437.  
  2438. DSeqPrintPrefs::~DSeqPrintPrefs()
  2439. {
  2440. }
  2441.  
  2442.  
  2443. inline Nlm_FonT GetAFont( char* fname, short fsize, short fstyle)
  2444. {
  2445.     if (StrICmp(fname,"System")==0) return Nlm_systemFont;
  2446.     else if (StrICmp(fname,"Program")==0) return Nlm_programFont;
  2447.     else return Nlm_GetFont( fname, fsize, 
  2448.              fstyle & kBold, fstyle & kItalic, fstyle & kUnderline, NULL);
  2449. }
  2450.  
  2451. // static
  2452. void DSeqPrintPrefs::InitGlobals() 
  2453.  
  2454.     gNameFontName= gApplication->GetPref( "gNameFontName", "fonts", gNameFontName);
  2455.     gNameFontSize= gApplication->GetPrefVal( "gNameFontSize", "fonts", "10");
  2456.     gNameStyle= gApplication->GetPrefVal( "gNameStyle", "fonts", "0");
  2457.     gNameFont= ::GetAFont(gNameFontName,gNameFontSize, gNameStyle);
  2458.  
  2459.     gBaseFontName= gApplication->GetPref( "gBaseFontName", "fonts", gBaseFontName);
  2460.     gBaseFontSize= gApplication->GetPrefVal( "gBaseFontSize", "fonts", "10");
  2461.     gBaseStyle= gApplication->GetPrefVal( "gBaseStyle", "fonts", "0");
  2462.     gBaseFont= ::GetAFont(gBaseFontName,gBaseFontSize, gBaseStyle);
  2463.  
  2464.     gIndexFontName= gApplication->GetPref( "gIndexFontName", "fonts", gIndexFontName);
  2465.     gIndexFontSize= gApplication->GetPrefVal( "gIndexFontSize", "fonts", "9");
  2466.     gIndexStyle= gApplication->GetPrefVal( "gIndexStyle", "fonts", "0");
  2467.     gIndexFont= ::GetAFont(gIndexFontName,gIndexFontSize, gIndexStyle);
  2468.     
  2469.     gNameLeft= gApplication->GetPrefVal( "gNameLeft", "seqprint","0");
  2470.     gNameRight= gApplication->GetPrefVal( "gNameRight", "seqprint","1");
  2471.     gIndexLeft= gApplication->GetPrefVal( "gIndexLeft", "seqprint","1");
  2472.     gIndexRight= gApplication->GetPrefVal( "gIndexRight", "seqprint","0");
  2473.     gIndexTop= gApplication->GetPrefVal( "gIndexTop", "seqprint","1");
  2474.     gColored= gApplication->GetPrefVal( "gColored", "seqprint","1");
  2475.     gBasesPerLine= gApplication->GetPrefVal( "gBasesPerLine", "seqprint","60");
  2476.   
  2477.     gShowComplement= gApplication->GetPrefVal( "gShowComplement", "seqprint","1");
  2478.     gThreeLetAA= gApplication->GetPrefVal( "gThreeLetAA", "seqprint","0");
  2479.     gOnlyORF= gApplication->GetPrefVal( "gOnlyORF", "seqprint","0");
  2480.     gShowAA1= gApplication->GetPrefVal( "gShowAA1", "seqprint","0");
  2481.     gShowAA2= gApplication->GetPrefVal( "gShowAA2", "seqprint","0");
  2482.     gShowAA3= gApplication->GetPrefVal( "gShowAA3", "seqprint","0");
  2483.     gShowCompAA1= gApplication->GetPrefVal( "gShowCompAA1", "seqprint","0");
  2484.     gShowCompAA2= gApplication->GetPrefVal( "gShowCompAA2", "seqprint","0");
  2485.     gShowCompAA3= gApplication->GetPrefVal( "gShowCompAA3", "seqprint","0");
  2486.  
  2487.     gShowAllZymes= gApplication->GetPrefVal( "gShowAllZymes", "remap","0");
  2488.     gShowCutpoints= gApplication->GetPrefVal( "gShowCutpoints", "remap","0");
  2489.     gShowNoncutters= gApplication->GetPrefVal( "gShowNoncutters", "remap","0");
  2490.     gShowExcludedCutters= gApplication->GetPrefVal( "gShowExcludedCutters", "remap","0");
  2491.  
  2492.     gREMinCuts= gApplication->GetPrefVal( "gREMinCuts", "remap","1");
  2493.     gREMaxCuts= gApplication->GetPrefVal( "gREMaxCuts", "remap","999");
  2494.  
  2495. #if 0
  2496.     {
  2497.     char* srect = gApplication->GetPref( "gSeqPrintDocRect", "windows", "20 20 450 220");
  2498.         // sscanf is failing on Mac/codewar !? used to work
  2499.     if (srect) {
  2500.         char* cp= srect;
  2501.         while (*cp && isspace(*cp)) cp++;
  2502.         gSeqPrintDocRect.left= atoi( cp);
  2503.         
  2504.         while (*cp && !isspace(*cp)) cp++;
  2505.         while (*cp && isspace(*cp)) cp++;
  2506.         gSeqPrintDocRect.top= atoi( cp);
  2507.         
  2508.         while (*cp && !isspace(*cp)) cp++;
  2509.         while (*cp && isspace(*cp)) cp++;
  2510.         gSeqPrintDocRect.right= atoi( cp);
  2511.         
  2512.         while (*cp && !isspace(*cp)) cp++;
  2513.         while (*cp && isspace(*cp)) cp++;
  2514.         gSeqPrintDocRect.bottom= atoi( cp);
  2515.         }
  2516.     MemFree(srect);
  2517.     }    
  2518. #endif
  2519.  
  2520. }
  2521.  
  2522.  
  2523. //static
  2524. void DSeqPrintPrefs::SaveGlobals() 
  2525. {
  2526.     gApplication->SetPref( gNameFontName, "gNameFontName", "fonts");
  2527.     gApplication->SetPref( gNameFontSize, "gNameFontSize", "fonts");
  2528.     gApplication->SetPref( gNameStyle, "gNameStyle", "fonts");
  2529.     gApplication->SetPref( gBaseFontName, "gBaseFontName", "fonts");
  2530.     gApplication->SetPref( gBaseFontSize, "gBaseFontSize", "fonts");
  2531.     gApplication->SetPref( gBaseStyle, "gBaseStyle", "fonts");
  2532.     gApplication->SetPref( gIndexFontName, "gIndexFontName", "fonts");
  2533.     gApplication->SetPref( gIndexFontSize, "gIndexFontSize", "fonts");
  2534.     gApplication->SetPref( gIndexStyle, "gIndexStyle", "fonts");
  2535.     
  2536.     gApplication->SetPref( gNameLeft, "gNameLeft", "seqprint");
  2537.     gApplication->SetPref( gNameRight, "gNameRight", "seqprint");
  2538.     gApplication->SetPref( gIndexLeft, "gIndexLeft", "seqprint");
  2539.     gApplication->SetPref( gIndexRight, "gIndexRight", "seqprint");
  2540.     gApplication->SetPref( gIndexTop, "gIndexTop", "seqprint");
  2541.     gApplication->SetPref( gColored, "gColored", "seqprint");
  2542.     gApplication->SetPref( gBasesPerLine, "gBasesPerLine", "seqprint");
  2543.     
  2544. // restrict map
  2545.     gApplication->SetPref( gShowComplement, "gShowComplement", "seqprint");
  2546.     gApplication->SetPref( gThreeLetAA, "gThreeLetAA", "seqprint");
  2547.     gApplication->SetPref( gOnlyORF, "gOnlyORF", "seqprint");
  2548.     
  2549.     gApplication->SetPref( gShowAA1, "gShowAA1", "seqprint");
  2550.     gApplication->SetPref( gShowAA2, "gShowAA2", "seqprint");
  2551.     gApplication->SetPref( gShowAA3, "gShowAA3", "seqprint");
  2552.     gApplication->SetPref( gShowCompAA1, "gShowCompAA1", "seqprint");
  2553.     gApplication->SetPref( gShowCompAA2, "gShowCompAA2", "seqprint");
  2554.     gApplication->SetPref( gShowCompAA3, "gShowCompAA3", "seqprint");
  2555.  
  2556. // rest. map tables
  2557.     gApplication->SetPref( gShowAllZymes, "gShowAllZymes", "remap");
  2558.     gApplication->SetPref( gShowCutpoints, "gShowCutpoints", "remap");
  2559.     gApplication->SetPref( gShowNoncutters, "gShowNoncutters", "remap");
  2560.     gApplication->SetPref( gShowExcludedCutters, "gShowExcludedCutters", "remap");
  2561.     gApplication->SetPref( gREMinCuts, "gREMinCuts", "remap");
  2562.     gApplication->SetPref( gREMaxCuts, "gREMaxCuts", "remap");
  2563.  
  2564. }
  2565.  
  2566.  
  2567.  
  2568.  
  2569. void DSeqPrintPrefs::NewFontCluster(char* title, DView* mainview,
  2570.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  2571.                     char* fontname, short fontstyle, short fontsize )
  2572. {    
  2573.         // Name style -- font, font size, font style
  2574.     DPopupMenu* popm;
  2575.     DSwitchBox* sw;
  2576.     DPrompt* pr;
  2577.     DView* super;
  2578.     
  2579.     super= mainview;
  2580.     super->NextSubviewBelowLeft();
  2581.  
  2582.     DCluster* maincluster= new DCluster( 0, super, 30, 10, true, NULL); //false, title);
  2583.     super= maincluster;
  2584.  
  2585.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Font  ");
  2586.     mfont= popm;
  2587.     popm->AddFonts();
  2588.     popm->SetFontChoice( fontname); 
  2589.     //super->NextSubviewToRight();
  2590.  
  2591.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Style  ");
  2592.     mstyle= popm;
  2593.     popm->AddItem( kStylePlain, "Plain", true);
  2594.     popm->AddItem( kStyleItalic, "Italic", true);
  2595.     popm->AddItem( kStyleBold, "Bold", true);
  2596.     popm->AddItem( kStyleUnderline, "Underline", true);
  2597.     popm->SetItemStatus( kStylePlain, fontstyle==0);
  2598.     popm->SetItemStatus( kStyleItalic, fontstyle & kItalic);
  2599.     popm->SetItemStatus( kStyleBold, fontstyle & kBold);
  2600.     popm->SetItemStatus( kStyleUnderline, fontstyle & kUnderline);
  2601.     //super->NextSubviewToRight();
  2602.     
  2603.     DCluster* cluster= new DCluster(0, super, 30, 10, true, NULL);
  2604.     super= cluster;
  2605.     
  2606.     pr= new DPrompt( 0, super, "font size", 0, 0, Nlm_programFont);             
  2607.     //super->NextSubviewToRight();
  2608.     super->NextSubviewBelowLeft();
  2609.     sw = new DSwitchBox(0, super, true, true);
  2610.     swsize= sw;
  2611.     sw->SetValues(fontsize,99);
  2612.     //super->NextSubviewBelowLeft();
  2613.  
  2614.     super= mainview;
  2615.     super->NextSubviewBelowLeft();
  2616. }
  2617.  
  2618.  
  2619. void DSeqPrintPrefs::Initialize() 
  2620.     DView* super;
  2621.     DPrompt* pr;
  2622.     DCheckBox* ck;
  2623.     DCluster* clu;
  2624.     char nums[128];    
  2625.  
  2626.     super= this;
  2627.     clu= new DCluster( 0, super, 30, 10, false, "Bases");
  2628.     super= clu;
  2629.  
  2630.     NewFontCluster( "Base style", super, fBaseFontMenu, fBaseStyleMenu, fBaseSizeSw,
  2631.                             gBaseFontName, gBaseStyle, gBaseFontSize);
  2632.  
  2633.     ck= new DCheckBox(cColored, super, "Color ");
  2634.     ck->SetStatus(gColored);
  2635.     super->NextSubviewToRight();
  2636.     
  2637.     sprintf( nums, "%d", gBasesPerLine);
  2638.     fBasePerLine= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  2639.     this->SetEditText( fBasePerLine);
  2640.     super->NextSubviewToRight();
  2641.     pr= new DPrompt( 0, super, "bases/line", 0, 0, Nlm_programFont);             
  2642.  
  2643.     super = this;
  2644.     //super->NextSubviewToRight();
  2645.     //super->NextSubviewBelowLeft();
  2646.  
  2647.     clu= new DCluster( 0, super, 30, 10, false, "Indices");
  2648.     super= clu;
  2649.  
  2650.     NewFontCluster( "Index style", super, fIndexFontMenu, fIndexStyleMenu, fIndexSizeSw,
  2651.                             gIndexFontName, gIndexStyle, gIndexFontSize);
  2652.  
  2653.     ck= new DCheckBox(cIndexLeft, super, "Left");
  2654.     ck->SetStatus(gIndexLeft);
  2655.     ck= new DCheckBox(cIndexRight, super, "Right");
  2656.     ck->SetStatus(gIndexRight);
  2657.     ck= new DCheckBox(cIndexTop, super, "Top");
  2658.     ck->SetStatus(gIndexTop);
  2659.  
  2660.     super = this;
  2661.     //super->NextSubviewToRight();
  2662.     //super->NextSubviewBelowLeft();
  2663.  
  2664.     clu= new DCluster( 0, super, 30, 10, false, "Names");
  2665.     super= clu;
  2666.  
  2667.     NewFontCluster( "Name style", super, fNameFontMenu, fNameStyleMenu, fNameSizeSw,
  2668.                             gNameFontName, gNameStyle, gNameFontSize);
  2669.  
  2670.     ck= new DCheckBox(cNameLeft, super, "Left");
  2671.     ck->SetStatus(gNameLeft);
  2672.     ck= new DCheckBox(cNameRight, super, "Right");
  2673.     ck->SetStatus(gNameRight);
  2674.     
  2675.     super = this;
  2676.     //super->NextSubviewToRight();
  2677.     //super->NextSubviewBelowLeft();
  2678.  
  2679. #if 1        
  2680.  
  2681.                 // turn this into 2nd dialog window...
  2682.                 
  2683.     clu= new DCluster( 0, super, 30, 10, false, "Restriction Maps");
  2684.     super= clu;
  2685.  
  2686.     ck= new DCheckBox(cShowComplement, super, "Show Complement");
  2687.     ck->SetStatus(gShowComplement);
  2688.     super->NextSubviewBelowLeft();
  2689.     
  2690.     DCluster* pclu= new DCluster( 0, super, 30, 10, false, "Protein translate frame");
  2691.     super= pclu;
  2692.     pr= new DPrompt( 0, super, " sequence", 0, 0, Nlm_programFont);             
  2693.     super->NextSubviewToRight();
  2694.     ck= new DCheckBox(cShowAA1, super, "1st");
  2695.     ck->SetStatus(gShowAA1);
  2696.     super->NextSubviewToRight();
  2697.     ck= new DCheckBox(cShowAA2, super, "2nd");
  2698.     ck->SetStatus(gShowAA2);
  2699.     super->NextSubviewToRight();
  2700.     ck= new DCheckBox(cShowAA3, super, "3rd");
  2701.     ck->SetStatus(gShowAA3);
  2702.     super->NextSubviewBelowLeft();
  2703.  
  2704.     pr= new DPrompt( 0, super, "complement", 0, 0, Nlm_programFont);             
  2705.     super->NextSubviewToRight();
  2706.     ck= new DCheckBox(cShowCompAA1, super, "1st");
  2707.     ck->SetStatus(gShowCompAA1);
  2708.     super->NextSubviewToRight();
  2709.     ck= new DCheckBox(cShowCompAA2, super, "2nd");
  2710.     ck->SetStatus(gShowCompAA2);
  2711.     super->NextSubviewToRight();
  2712.     ck= new DCheckBox(cShowCompAA3, super, "3rd");
  2713.     ck->SetStatus(gShowCompAA3);
  2714.  
  2715.     super->NextSubviewBelowLeft();
  2716.     ck= new DCheckBox(cThreeLetAA, super, "3-letter code");
  2717.     ck->SetStatus(gThreeLetAA);
  2718.     super->NextSubviewToRight();
  2719.     ck= new DCheckBox(cOnlyORF, super, "ORFs only");
  2720.     ck->SetStatus(gOnlyORF);
  2721.     super= clu;
  2722.     super->NextSubviewBelowLeft();
  2723.  
  2724.     DCluster* rclu= new DCluster( 0, super, 30, 10, false, "Restriction enzymes");
  2725.     super= rclu;
  2726.  
  2727.     pr= new DPrompt( 0, super, "Min. cuts", 0, 0, Nlm_programFont);             
  2728.     super->NextSubviewToRight();
  2729.     sprintf( nums, "%d", gREMinCuts);
  2730.     fREMinCuts= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  2731.     this->SetEditText( fREMinCuts);
  2732.     pr= new DPrompt( 0, super, "Max. cuts", 0, 0, Nlm_programFont);             
  2733.     super->NextSubviewToRight();
  2734.     sprintf( nums, "%d", gREMaxCuts);
  2735.     fREMaxCuts= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  2736.     super->NextSubviewBelowLeft();
  2737.  
  2738.     pr= new DPrompt( 0, super, "Tables", 0, 0, Nlm_programFont);             
  2739.     super->NextSubviewToRight();
  2740.     ck= new DCheckBox(cShowCutpoints, super, "Cutpoints");
  2741.     ck->SetStatus(gShowCutpoints);
  2742.     ck= new DCheckBox(cShowAllZymes, super, "All zymes");
  2743.     ck->SetStatus(gShowAllZymes);
  2744.     super->NextSubviewBelowLeft();
  2745.     ck= new DCheckBox(cShowNoncutters, super, "Noncutters");
  2746.     ck->SetStatus(gShowNoncutters);
  2747.     ck= new DCheckBox(cShowExcludedCutters, super, "Excluded cutters");
  2748.     ck->SetStatus(gShowExcludedCutters);
  2749.  
  2750.     super= clu;
  2751.  
  2752.     super= this;
  2753. #endif
  2754.  
  2755.     this->AddOkayCancelButtons();
  2756.     
  2757. }
  2758.  
  2759.  
  2760. void DSeqPrintPrefs::OkayAction() 
  2761.     short             aSize, aStyle;
  2762.     char            name[256], *nums;
  2763.     DMenu     *    aFontMenu, * aStyleMenu;
  2764.     Nlm_FonT    aFont;
  2765.     
  2766.     if (fREMinCuts) {
  2767.         nums= fREMinCuts->GetTitle(name, sizeof(name));
  2768.         gREMinCuts= atol(nums);
  2769.         }
  2770.     if (fREMaxCuts) {
  2771.         nums= fREMaxCuts->GetTitle(name, sizeof(name));
  2772.         gREMaxCuts= atol(nums);
  2773.         }
  2774.     if (fBasePerLine) {
  2775.         nums= fBasePerLine->GetTitle(name, sizeof(name));
  2776.         gBasesPerLine= atol(nums);
  2777.         }
  2778.     
  2779.     for (short imenu= 0; imenu<3; imenu++) {
  2780.         
  2781.         switch (imenu) {
  2782.           case 0:
  2783.                 aFontMenu= fNameFontMenu; 
  2784.                 aStyleMenu= fNameStyleMenu; 
  2785.                 aSize= fNameSizeSw->GetValue();// aSize= gNameFontSize;
  2786.               break;
  2787.           case 1:
  2788.                 aFontMenu= fBaseFontMenu; 
  2789.                 aStyleMenu= fBaseStyleMenu; 
  2790.                 aSize= fBaseSizeSw->GetValue();// aSize= gBaseFontSize;
  2791.               break;
  2792.           case 2:
  2793.                 aFontMenu= fIndexFontMenu; 
  2794.                 aStyleMenu= fIndexStyleMenu; 
  2795.                 aSize= fIndexSizeSw->GetValue();// aSize= gIndexFontSize;
  2796.               break;
  2797.           }
  2798.             
  2799.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  2800.             aStyle= 0;
  2801. #ifdef WIN_MAC
  2802.             if (!aStyleMenu->GetItemStatus(kStylePlain)) {
  2803.                 if (aStyleMenu->GetItemStatus(kStyleItalic   )) aStyle |= kItalic;
  2804.                 if (aStyleMenu->GetItemStatus(kStyleBold     )) aStyle |= kBold;
  2805.                 if (aStyleMenu->GetItemStatus(kStyleUnderline)) aStyle |= kUnderline;
  2806.                 }
  2807. #else
  2808.              short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  2809.              switch (item) {
  2810.                  case 1: aStyle= 0; break;
  2811.                  case 2: aStyle |= kItalic; break;
  2812.                  case 3: aStyle |= kBold; break;
  2813.                  case 4: aStyle |= kUnderline; break;
  2814.          }
  2815. #endif             
  2816.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  2817.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  2818.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, 
  2819.                                                     aStyle & kItalic, aStyle & kUnderline, NULL);
  2820.             
  2821.             switch (imenu) {
  2822.               case 0: 
  2823.               if (aSize != gNameFontSize || aStyle != gNameStyle || StringCmp(name,gNameFontName)!=0) {
  2824.                     if (gNameFontName) MemFree(gNameFontName);
  2825.                     gNameFontName= StrDup(name);
  2826.                     gNameFont= aFont;
  2827.                     gNameFontSize= aSize;
  2828.                     gNameStyle= aStyle;
  2829.                     fNeedSave= true;
  2830.                     }
  2831.                   break;
  2832.                   
  2833.               case 1: 
  2834.               if (aSize != gBaseFontSize || aStyle != gBaseStyle || StringCmp(name,gBaseFontName)!=0) {
  2835.                     if (gBaseFontName) MemFree(gBaseFontName);
  2836.                     gBaseFontName= StrDup(name);
  2837.                     gBaseFont= aFont;
  2838.                     gBaseFontSize= aSize;
  2839.                     gBaseStyle= aStyle;
  2840.                     fNeedSave= true;
  2841.                     }
  2842.                   break;
  2843.                   
  2844.               case 2: 
  2845.               if (aSize != gIndexFontSize || aStyle != gBaseStyle || StringCmp(name,gIndexFontName)!=0) {
  2846.                     if (gIndexFontName) MemFree(gIndexFontName);
  2847.                     gIndexFontName= StrDup(name);
  2848.                     gIndexFont= aFont;
  2849.                     gIndexFontSize= aSize;
  2850.                     gIndexStyle= aStyle;
  2851.                     fNeedSave= true;
  2852.                     }
  2853.                   break;
  2854.               }
  2855.               
  2856.             }
  2857.         }
  2858.     
  2859. #if 0
  2860. #if 1
  2861.     // CurrentWindow gets prefs dlog window, not one we want    
  2862.     //DSeqPrintDoc* awin= (DSeqPrintDoc*) gWindowManager->CurrentWindow();
  2863.     DList* wins= gWindowManager->GetWindowList();
  2864.     if (wins) {
  2865.         short last1= wins->GetSize() - 2;
  2866.         if (last1>0) {
  2867.             DSeqPrintDoc* awin= (DSeqPrintDoc*) wins->At(last1);
  2868.             if (awin && awin->Id() == DSeqPrintDoc::kSeqPrintDoc) {
  2869.                 awin->fView->Initialize();
  2870.                 awin->fView->GetReadyToShow();
  2871.                 awin->fView->Invalidate();
  2872.                 }
  2873.             }
  2874.         }
  2875. #else    
  2876.     DList* wins= gWindowManager->GetWindowList();
  2877.     if (wins) {
  2878.         long i, nwin= wins->GetSize();
  2879.         for (i= nwin-1; i>=0; i--) {
  2880.             DSeqPrintDoc* awin= (DSeqPrintDoc*) wins->At(i);
  2881.             if (awin && awin->Id() == DSeqPrintDoc::kSeqPrintDoc) {
  2882.                 awin->fView->Initialize();
  2883.                 awin->fView->GetReadyToShow();
  2884.                 awin->fView->Invalidate();
  2885.                 break; // do only 1st we find ...
  2886.                 }
  2887.             }
  2888.         }
  2889. #endif        
  2890. #endif
  2891.  
  2892. }
  2893.  
  2894.  
  2895.  
  2896. Boolean DSeqPrintPrefs::IsMyAction(DTaskMaster* action) 
  2897. {    
  2898.     DView* aview= (DView*) action;
  2899.     
  2900.     switch (action->Id()) {
  2901.  
  2902.         case cIndexLeft : gIndexLeft= aview->GetStatus(); break;
  2903.         case cIndexRight: gIndexRight= aview->GetStatus(); break;
  2904.         case cIndexTop  : gIndexTop= aview->GetStatus(); break;
  2905.         case cNameLeft    : gNameLeft= aview->GetStatus(); break;
  2906.         case cNameRight    : gNameRight= aview->GetStatus(); break;
  2907.         case cColored        : gColored= aview->GetStatus(); break;
  2908.  
  2909.         case cShowComplement: gShowComplement= aview->GetStatus(); break;
  2910.         case cThreeLetAA    : gThreeLetAA= aview->GetStatus(); break;
  2911.         case cOnlyORF    : gOnlyORF= aview->GetStatus(); break;
  2912.         case cShowAA1    : gShowAA1= aview->GetStatus(); break;
  2913.         case cShowAA2    : gShowAA2= aview->GetStatus(); break;
  2914.         case cShowAA3    : gShowAA3= aview->GetStatus(); break;
  2915.         case cShowCompAA1    : gShowCompAA1= aview->GetStatus(); break;
  2916.         case cShowCompAA2    : gShowCompAA2= aview->GetStatus(); break;
  2917.         case cShowCompAA3    : gShowCompAA3= aview->GetStatus(); break;
  2918.         case cShowCutpoints    : gShowCutpoints= aview->GetStatus(); break;
  2919.         case cShowAllZymes    : gShowAllZymes= aview->GetStatus(); break;
  2920.         case cShowNoncutters    : gShowNoncutters= aview->GetStatus(); break;
  2921.         case cShowExcludedCutters    : gShowExcludedCutters= aview->GetStatus(); break;
  2922.  
  2923.         default : return DWindow::IsMyAction(action);    
  2924.         }
  2925.         
  2926.     fNeedSave= true;
  2927.     return true;
  2928. }
  2929.  
  2930.  
  2931. void DSeqPrintPrefs::Open()
  2932. {
  2933.     DWindow::Open();
  2934. }
  2935.  
  2936. void DSeqPrintPrefs::Close()
  2937. {
  2938.     if (fNeedSave) {
  2939.         DSeqPrintPrefs::SaveGlobals();
  2940.         fNeedSave= false;
  2941.         }
  2942.     DWindow::Close();
  2943. }
  2944.  
  2945.  
  2946.  
  2947.     // global calling function
  2948. void SeqPrintPrefs(short id)
  2949. {
  2950.     switch (id) {
  2951.     
  2952.         case kSeqPrintPrefInit: 
  2953.             DSeqPrintPrefs::InitGlobals(); 
  2954.             break;
  2955.     
  2956.         case kSeqPrintPrefDialog:
  2957.             if (!gSeqPrintPrefs) {
  2958.                 gSeqPrintPrefs = new DSeqPrintPrefs();
  2959.                 gSeqPrintPrefs->Initialize();
  2960.                 }
  2961.             if (gSeqPrintPrefs && gSeqPrintPrefs->PoseModally()) ;
  2962.             break;
  2963.             
  2964.         case kAlnPrintPrefDialog:
  2965.         case kREMapPrefDialog:
  2966.             break;
  2967.     }
  2968.     
  2969. }
  2970.  
  2971.  
  2972.